Re:Playing with Syntax
by PrettyButUgly on Saturday August 20, 2016 @04:49PM
(#12328261)
I'm not much for Common Lisp, but I do think Scheme is the prettiest language in which people write ugly code. As such, while I am sympathetic to the virtues of s-expressions, this example is not going to win any hearts or minds. I don't much care for Python's performance or newer features, but your snippet screams for a comparison:
That really seems much more clear than the gymnastics my mind has to do manually pairing the assignments inside of psetf. I won't argue that it's objectively better syntax, but I still think it is.
[ Parent
| on HN ]
Re:Playing with Syntax
by qwertyuiop924 on Sunday August 21, 2016 @12:24PM
(#12331448)
Well...
(define-syntax assign-group!
(ir-macro-transformer
(lambda (x i c)
(let ((vars (cadr x))
(vals (caddr x)))
`(let ,(map (lambda (var val) '(var val)) vars vals)
,@(map (lambda (var)
`(set! ,(i var) ,var)) vars))))))
Mind, I haven't tested this, because I don't have CHICKEN Scheme (the dialect this is written in) in front of me, and I may not have matched all the parens on the end, but it should work like this: (assign-group! (a b c) (c a b))
Giving you your nice assigment syntax you wanted.That's the nice thing about Lisps: if you don't like it, you can change it.
Re:Playing with Syntax
by qwertyuiop924 on Monday August 22, 2016 @03:29PM
(#12338751)
There is in fact one error in the above macro: well, I think only one: in the map, (lambda (var val) '(var val)) should be (lambda (var val) (list var val))
That's why I mentioned rotatef:
(rotatef a c b) ;; a <-- c <-- b
;; `--->----->-'You forgot "else:"
Re:Playing with Syntax
by PrettyButUgly on Saturday August 20, 2016 @07:57PM
(#12328847)
Funny that. In my head, I parsed it as two (odd) statements under one if statement. More like when than if.