|
|
Invisible escreveu:
> nemesis wrote:
>> Not at all. Prefix syntax makes everything very clear: most
>> everything in the begining of a list is a function or macro and the
>> rest are arguments, like
>> (+ 1 i) or ((lambda (x) (* x x)) 3)
>
> I'm having trouble seeing which thing a given subexpression is the
> argument to. To do that, you have to count brackets. It's not
> impossible, just not very easy.
Lispers just forget the parentheses and look at the indented code.
Parentheses are only important for macros and structured editing.
Post a reply to this message
|
|
|
|
>>> (+ 1 i) or ((lambda (x) (* x x)) 3)
>>
>> I'm having trouble seeing which thing a given subexpression is the
>> argument to. To do that, you have to count brackets. It's not
>> impossible, just not very easy.
>
> Lispers just forget the parentheses and look at the indented code.
> Parentheses are only important for macros and structured editing.
Well, if you already know how many parameters each function takes, that
could work. It still doesn't help when multiple parameterisations are
valid though...
(Also, the example you mosted has some fairly unhelpful indentation in it.)
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
|
|
|
Orchid XP v8 wrote:
> Well, if you already know how many parameters each function takes, that
> could work.
In the example I gave, all functions are known, because they are locally
defined. Other than that:
*lambda* creates a new function by taking a list of parameters and
several subexpressions as body => (lambda (p1 p2 ...) body ...)
*let* takes a list of local bindings and then may have several
subexpressions as body => (let ((b1 v1) (b2 v2) ...) body ...)
let is just a macro for ((lambda (b1 b2 ...) body ...) v1 v2 ...)
That is, the application of values to the function. :)
*if* takes a condition and has at least one branch => (if foo this) or
(if foo this that)
*or* takes several subexpressions and evaluates them with logical or
=> (or foo bar ...)
> (Also, the example you mosted has some fairly unhelpful indentation in it.)
BTW, it's problem 1 from Euler, except twisted a bit. I didn't know you
already knew of it. :P
(let ((%? (lambda (a b) (zero? (modulo a b)))))
(let sum ((i 5) (r 0))
(if (= i 100000) r
(sum (+ 1 i) (if (or (%? i 5) (%? i 7))
(+ r i)
r)))))
I don't think it's particularly bad indented. In named lets, I tend to
call it like a function, all parameters in the same line. Lisp
indenting generally puts only the first parameter in the same line, the
others go below, indented at the same line as the first parameter.
Anyway, it reads like this:
> (let ((%? (lambda (a b) (zero? (modulo a b)))))
let %? be a function taking a b as arguments and saying if a is
divisible by b
> (let sum ((i 5) (r 0))
then let sum be a function taking (i initially 5) and (r initially 0)
> (if (= i 100000) r
and returning r if i == 100000
> (sum (+ 1 i) (if (or (%? i 5) (%? i 7))
> (+ r i)
> r)))))
or sum of (incremented i) and ((r+i) -- if i divisible by 5 or by 7 --
(or r otherwise))
Is it really that hard? Perhaps I've lost my mind in parentheses and
can now see clearly through the Matrix code stream... :D
Post a reply to this message
|
|