I wonder how programming language based on fusional natural languages with cases could work.
Some ideas (warning - long and useless read):
- everything is an expression
- expressions have Cases. Default case (without postfixes) is Source Case
- cases are like roles for parts of expression in given complex expression context (allow us to change order of arguments in expressions without named parameters for example, and to overload functions/macros depending on Cases of the supplied arguments)
- you can define pre-, -post, and -in- fixes that work like macros/functions
- you can use pre/post fixes to tag expression with cases in the context of an expression
- you can use 1-arg functions/macros as pre and postfixes, or as regular functions
- you can use 2-arg functions/macros as infixes or as regular functions
- more than 2arg functions can only be used as regular functions
- you can overload functions/macros depending on case of args
- you can define your own cases
Example:
% %1 %2 etc are unamed arguments in
macro/function definitions,
like in lambdas in clojure
"-" is used in pre/in/post fixed macros
definitions to mark where the base
identifier goes
%-! is 1arg macro that defines variable of name %.
Example:
a!
foobar!
%-a is postfix macro that tags variable %
with Target case
%-i tags with Helper case
%-p tags with PositiveConditional case
%-n tags with NegativeConditional case
%1a=%2 is infix 2arg macro that assigns to
variable %1 (must be in Target case)
value %2 (in Source case).
Can be used as regular macro:
= %1a %2
or equivalently
= %2 %1a
We can also overload = to be equality operator
if both args are in Source case
%1=%2
works with regular macro too:
= %1 %2
or
= %2 %1
We can overload binary operators with 3rd and 4th args in PositiveConditional and NegativeConditional cases and we don't need IFs :)
This also allows us to write if with only else clause in the form:
> x 0 (OUTPUTa="X SMALLER THAN 0!!!")n
%1-;-%2 is infix macro that evaluates in sequence.
It's overloaded for all cases, especially
for %1a-;-%2a
# is python-style comment
Example code to calculate real roots of quadratic equation:
a! b! c! delta! # definitions of variables
= INPUT aa ba ca # overloaded = macro with
# many targets (a b c in Target case)
# and one source
# to easily fetch many items from input
deltaa=((b^2)-4*a*c) # precedence will be a problem
# to define generally
= delta 0 # overloaded = equality test with
# 3rd arg being positive conditional case
# and 4th being negative conditional case
(
= OUTPUTa "x0=" (-b/(2*a)) # overloaded = macro with one target
# and many sources - will join the sources
)p
(> delta 0
(
= OUTPUTa "x0=" (-b-sqrt(delta))/(2*a);
= OUTPUTa "x1=" (-b+sqrt(delta))/(2*a)
)p
)n
I know a bit of Finnish, and I can imagine that a programming language built on the principles of Finnish grammar would be beautifully expressive as well as extremely terse.
For example, maybe '-ss' denotes 'class'. Functions and methods with '-ef' with an optional return type '-int', '-ing' (string), '-oat' (float). Start a loop iterator by adding '-oop' to an iterable? Modify conditionals change their behaviour, e.g. 'ifret' (if/return) etc
Fooss:
barefint:
thingoop(i)
ifret i == someValue
Looks strange, but I if you're used to the concept I wonder if it would be more efficient.
Some ideas (warning - long and useless read):
- everything is an expression
- expressions have Cases. Default case (without postfixes) is Source Case
- cases are like roles for parts of expression in given complex expression context (allow us to change order of arguments in expressions without named parameters for example, and to overload functions/macros depending on Cases of the supplied arguments)
- you can define pre-, -post, and -in- fixes that work like macros/functions
- you can use pre/post fixes to tag expression with cases in the context of an expression
- you can use 1-arg functions/macros as pre and postfixes, or as regular functions
- you can use 2-arg functions/macros as infixes or as regular functions
- more than 2arg functions can only be used as regular functions
- you can overload functions/macros depending on case of args
- you can define your own cases
Example:
Example: Can be used as regular macro: We can also overload = to be equality operator if both args are in Source case We can overload binary operators with 3rd and 4th args in PositiveConditional and NegativeConditional cases and we don't need IFs :)This also allows us to write if with only else clause in the form: