Garth Goldwater
07/22/2020, 9:17 PM(function-name arg1 arg2 arg3)
and not (function-name (arg1 arg2 arg3))
or in clojure: (function-name [arg1 arg2 arg3])
opeispo
07/22/2020, 9:20 PMKartik Agaram
function-name(arg1 arg2 arg3)
. What would be the advantages of this approach, Garth?Jimmy Miller
(function-name (arg1 arg2 arg3))
would have to have different evaluation semantics. Typically if you see (something here)
it is a list and if it isn't quoted then it is a going to be interpreted as a function call.
So with this change you'd have to say that things are only function calls if their first argument is a list and functions only can take 1 argument (i.e. (function-name (arg1) (arg2))
would be undefined? What would (f x)
now mean? Would it just be like a quoted list?
Of course, you wouldn't want (arg1 arg2 arg3)
to be an actual list, because now you have allocate just to call a function so it is just syntatic grouping but at the macro level it is of course still a list.
In general, it would make syntax more awkward (just think about math). It would make the evaluation semantics much more awkward.Garth Goldwater
07/22/2020, 9:46 PMDoug Moen
07/22/2020, 9:47 PMGarth Goldwater
07/22/2020, 9:47 PMGarth Goldwater
07/22/2020, 9:49 PMGarth Goldwater
07/22/2020, 9:51 PMDoug Moen
07/22/2020, 9:52 PMGarth Goldwater
07/22/2020, 9:52 PMGarth Goldwater
07/22/2020, 9:53 PMKartik Agaram
Garth Goldwater
07/22/2020, 9:56 PMGarth Goldwater
07/22/2020, 9:57 PMopeispo
07/22/2020, 10:00 PMKartik Agaram
(function-name
(arg1 arg2 arg3)
(block1
block2
block3)
metadata1
...)
Garth Goldwater
07/22/2020, 10:40 PM(cons (append (cdr (call-site)) new-arg))
, but if you look at it from a destructuring perspective or even more like a prolog-esque unification, something like (completely made up syntax)
return (function-name (...args additional-argument))
makes more sense to me than return (function-name ...args additional-arg)
... i think. i may have just persuaded myself out of this discussion lolGarth Goldwater
07/22/2020, 10:45 PMKartik Agaram
Garth Goldwater
07/22/2020, 10:46 PMGarth Goldwater
07/22/2020, 10:49 PMS.M Mukarram Nainar
07/22/2020, 11:48 PM(apply fun (list arg1 arg2 arg3))
to be the default, with syntactic sugar for it. It feels odd, but you are correct in pointing out that while function calls are destructured as pairs, syntactically there is no indication that this is the case. But honestly I can't think of a way to make this work short of the usual fun(arg1 arg2)
syntax.
This is a bit unrelated, but it came to mind when thinking of uniform syntaxāin fennel-lang, unquoting something that isn't quasiquoted moves its evaluation to compile time, which kind of gives you something like "anonymous macros" for free, which I've always found really neat.Garth Goldwater
07/23/2020, 1:04 AM(apply (fun arglist))
, so that apply is the same kind of form as a function isāa tree-shape that dictates something about its children.
i REALLY like the sound of the fennel-lang thingāi hadnāt heard of it. thatās exactly the kind of symmetry i go bananas for, particularly because it sounds like it deals with a model of managing the order of interpretation/execution. thanks for pointing me to it! (for any lurkers the link is https://fennel-lang.org/ )Garth Goldwater
07/23/2020, 1:05 AMarglist
might have to be something analogous to boxed. idk. trying to figure out if i can make it all consistentS.M Mukarram Nainar
07/23/2020, 1:40 AMGarth Goldwater
07/23/2020, 2:10 AMDan Cook
07/23/2020, 4:40 AMDan Cook
07/23/2020, 5:08 AMDan Cook
07/23/2020, 5:19 AMJack Rusher
07/23/2020, 8:31 AM(apply (fun arglist))
is (apply (partial fun arglist))
in the usual semantics. Some of what you're thinking about might be illuminated by a quick look into dialects that assume function composition, like Shen.Jack Rusher
07/23/2020, 8:35 AMS.M Mukarram Nainar
07/23/2020, 9:39 AM'(a b c)
is not equivalent to (list a b c)
in exactly the topic of this discussionā`quote` does not evaluate its arguments, and list
does. So '(a (+ 2 3))
is self evaluating, but (list a (+ 2 3))
evaluates to '(a 5)
. It's for that reason that quote
requires a special case in an interpreter, but list
does not.wtaysom
07/23/2020, 10:23 AMDoug Moen
07/23/2020, 1:16 PMiām working on languages that are at a minimum frame-basedThanks for showing me the term "frame-based". I'm working on something similar, having problems finding prior art, and googling "frame-based" gave me this: https://www.greenfoot.org/frames/
Doug Moen
07/23/2020, 2:17 PMA call. f is an abstraction (function or macro). Abstractions always have a single argument, like in ML/Haskell. In a call, 'f' is an evaluated subexpression, like in Scheme.(f x y z)
A call chain. (f x y z) is sugar for (((f x) y) z). This gives us a natural syntax for invoking a curried function or macro.[a b c]
A list. The subexpressions a, b, c are evaluated, similar to (list a b c) in Lisp.List exprs and call exprs are orthogonal concepts. A list expr expresses the fundamental concept of an ordered sequence of expressions. It is a mistake to intertwine or complect list exprs with call exprs, because that creates complexity. A function has a single argument, but you can simulate multiple arguments using Currying, or by passing a list as an argument. There is no need for the 'apply' function. This is important for composability. Let's say that the + function takes a list of zero or more numbers, as it does in Scheme. Then you write (+ [a b c]). Suppose you want to abstract out the list [a b c], replace it with the variable x. No need for mental gymnastics, you just write (+ x). Macros can be curried. The 'let' macro has two curried arguments. For example,
(let [[x [a b c]]] (+ x))
In T-Lisp, every value is printed as a constructor expression. When you evaluate this printed representation, you reconstruct the original value. List values are printed as list expressions, eg [1 2 3]
. This is intuitive, easy to understand, useful.
One of my criticisms of Lisp is that the printed representation of a list is a function call, and this is confusing to non-experts. For example, in Lisp, the printed representation of (list 'a 2)
is (a 2)
. You can manually convert this to an expression that reconstructs the original list by writing '(a 2)
, but now you have lost composability (the ability to substitute like for like). You can't trivially abstract out one of the subexpressions and replace it with a variable containing the same value.
Here is empirical research supporting my complaint about list syntax in Lisp:
https://www.cs.kent.ac.uk/people/staff/dat/miranda/wadler87.pdf
The difference between (1 2 3) and (quote (1 2 3)) is subtle, and it inevitably confuses students. In particular, it plays havoc with the substitution model of evaluation.
Garth Goldwater
07/24/2020, 4:21 AMDan Cook
07/24/2020, 5:01 AMDan Cook
07/24/2020, 6:47 AMGarth Goldwater
07/24/2020, 1:53 PMDoug Moen
07/24/2020, 2:59 PMGarth Goldwater
07/24/2020, 3:10 PM