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>

Comments

Re: pragmas gem / library - language syntax pragmas - turn on th

By Gerald Bauer at 04/11/2019 - 16:25

Hello,

I've added 10+ more language syntax pragmas for ruby. The pragmas now include:

- Pattern Matcher
- Enum Type
- (Algebraic) Union Data Types (with Variants)
- Type Type
- Pretty Symbol Keys
- Struct Type
- Option / Maybe / Nullable
- Natural / Positive Integer Numbers
- Storage / State
- Auto Numbered Block Arguments / Parameters
- Do End-of-Line Block
- Typed Data Structures
- Typed Arrays
- Preprocessor Directives

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

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

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