DevHeads.net

pragmas gem / library - language syntax pragmas - turn on the future today or add your own ideas for easy (re)use for everyone - let's evolve the ruby language together by experimenting in the wild in a pragma(tic) way

Hello,

I've put together a new pragmas gem / library [1] for language syntax pragmas
that lets you turn on the future today or add your own ideas for easy
(re)use for everyone.

Let's evolve the ruby language together by experimenting in the wild
in a pragma(tic) way.

First language syntax pragmas include match patterns, enum and type
types, auto numbered arguments, and more. Example:

Pattern Matcher

Will replace (transform) lines starting with

```
| None =>
| Some(x) =>
```

to

```
None: ->()
Some: ->(x)
```

Example in the wild:

```
match Map.find( Current.sender, account_from.allowances ), {
| None => { failwith( "Not allowed to spend from", from ) },
| Some(allowed) => {
match is_nat(allowed - tokens), {
| None => { failwith( "Not enough allowance for
transfer", allowed ) },
| Some(allowed) => {
if allowed == 0.p
Map.remove( Current.sender, account_from.allowances )
else
Map.add( Current.sender, allowed, account_from.allowances )
end
}
}
}
}
```

turns into:

```
match Map.find( Current.sender, account_from.allowances ), {
None: ->() { failwith( "Not allowed to spend from", from ) },
Some: ->(allowed) {
match is_nat(allowed - tokens), {
None: ->() { failwith( "Not enough allowance for transfer",
allowed ) },
Some: ->(allowed) {
if allowed == 0.p
Map.remove( Current.sender, account_from.allowances )
else
Map.add( Current.sender, allowed, account_from.allowances )
end
}
}
}
}
```

Enum

Will replace (transform) lines starting with

```
enum Color = Red | Green | Blue
enum State = Fundraising | ExpiredRefund | Successful # or
enum State = Fundraising
| ExpiredRefund
| Successful
```

to

```
enum :Color, :red, :green, :blue
enum :State, :fundraising, :expired_refund, :successful
```

What's your idea / pragma? Yes, you can.

Happy coding in (future) ruby with pragmas. Cheers. Prost.

[1] <a href="https://github.com/s6ruby/pragmas" title="https://github.com/s6ruby/pragmas">https://github.com/s6ruby/pragmas</a>

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>