ELENA-LANG / elena-lang

ELENA is a general-purpose language with late binding. It is multi-paradigm, combining features of functional and object-oriented programming. Rich set of tools are provided to deal with message dispatching : multi-methods, message qualifying, generic message handlers, run-time interfaces
https://elena-lang.github.io/
MIT License
227 stars 23 forks source link

Extended statement templates #563

Closed arakov closed 7 months ago

arakov commented 1 year ago

Is your feature request related to a problem? Please describe. Expression patterns should be introduced

arakov commented 7 months ago

Several basic expression patterns can be introduced, allowing to make the operation pattern more readable:

if:is pattern :

import extensions;

class Proxy
{
   field _o;

   constructor(o)
   {
      _o := o
   }

   int cast()
      => _o;
}

guessWho(o)
{
   if (o :is int val)
   {
      console.printLine(o," can be converted to int=", val);
   };
}

public program()
{
   guessWho(2);
   guessWho(new Proxy(2));
}

foreach:in pattern:

foreach(char ch :in "abc")
{
    console.printLine(ch)
}
arakov commented 7 months ago

The issue is implemented in ELENA 6.0.7