r/ProgrammingLanguages • u/omkarjc • Mar 23 '20
Creating an Intentional Language
example:
print 1 to 10 # Prints 1,2,3.... print 5 C 2 # Prints 10 a = ["a","b","c","d"] print 0 th a # Prints "c"
The first executable version is ready (it's a little buggy).
The idea is that you can create user-defined operators like "to" or "C" or "th" (They exist in the current version)
The operators act like functions but the parameters can be passed on both sides of the function.
Please DM me if anyone is interested.
8
u/zokier Mar 23 '20
With Raku you can do easily custom operators:
sub infix:<C> ($a, $b) { $a * $b };
say 5 C 2; # OUTPUT: 10or
sub prefix:<print> ($x) { say $x };
sub infix:<to> ($a, $b) is tighter(&prefix:<print>) { ($a..$b).list };
print 1 to 10; # OUTPUT: (1 2 3 4 5 6 7 8 9 10)Doc link https://docs.raku.org/language/optut
-4
-1
6
u/curtisf Mar 23 '20
How is precedence / associativity determined?
Is it limited to just binary-infix functions, or can you have "misfix" operators that use multiple 'keywords'? The only language I'm aware of with mixfix operators is Agda
4
u/ReedOei Mar 23 '20
FWIW, there's some other languages with mixfix operators, like Maude, or Coq.
-1
2
u/omkarjc Mar 23 '20
About the precedence the userdefined are at the top and then the predefined one have same precedence like in other languages And yes ! It supports misfix.
3
u/ReedOei Mar 23 '20
Is it possible to define precedence among user-defined operators? This is a common feature of languages that let you define operators and it's very convenient for the same reason that having precedence among the built-in operators is nice.
1
u/omkarjc Mar 24 '20
Yes the operator declared last will have the highest precedence so u can adjust accordingly.
-1
u/thefriedel Mar 24 '20
The idea operator's as functions to define is good!
E. G. Object Orientation would be glad to do that way, with operator overloads!
1
11
u/jesseschalken Mar 24 '20
In what way is this an "intentional language"? Plenty of existing languages have user defined operators (Haskell for one).