Re:Ask HN: Has Hacker News been hacked/cracked?
by pg on Tuesday March 17, 2009 @02:59AM
(#519546)
I generally tried to err on the side of flexibility, and it seemed more flexible not to require the lengths to match. I could imagine cases where you might want to use patterns both longer and shorter than the lists they were matched against. On the other hand, I'm not sure I've ever ended up taking advantage of this.
[ Parent
| on HN ]
Re:Ask HN: Has Hacker News been hacked/cracked?
by IHackedHN on Tuesday March 17, 2009 @03:15AM
(#519558)
Maybe you could use something along the lines of &rest to optionally support a pattern shorter than the matched list?
You could do that with a dot now. The trouble is, you end up creating a junk variable:
arc> (let (x . y) '(a b c) y)
(b c)
Re:Ask HN: Has Hacker News been hacked/cracked?
by IHackedHN on Tuesday March 17, 2009 @03:34AM
(#519573)
Making users create junk variables seems to me like better behavior than the current implicit behavior. It's your decision, though, of course.
Anyway, is it safe to assume that you're not going to try to get me arrested or anything?
I feel like unnecessary variables are extra bad; in cognitive terms they feel like they add more than one token to the length of a program.
Do you mean your username is actually descriptive? Since you are obviously a Lisp hacker, I'd be happy to have a truce. Can you send me an email?
Re:Ask HN: Has Hacker News been hacked/cracked?
by IHackedHN on Tuesday March 17, 2009 @04:34AM
(#519612)
Thank you. I've sent you an email.
Re:Ask HN: Has Hacker News been hacked/cracked?
by wingo on Tuesday March 17, 2009 @05:22AM
(#519638)
You don't have to name it. It could be _.
(let (x . _) '(a b c) x)
It sounds like you're treating list destructuring like CL's mvbind. While it's subjective of course, I'm more comfortable with the runtime doing what I mean when I control the number of values (modulo `(apply values ...)').I'm not comfortable with destructuring values "flexibly" when I don't control the data coming in.
Re:Ask HN: Has Hacker News been hacked/cracked?
by parenthesis on Tuesday March 17, 2009 @11:45AM
(#520000)
Except "_" is a perfectly good name for a symbol in Arc.
"nil" could be used instead, since nil isn't allowed to be rebound.
(let (x . nil) '(a b c) x)
even works already, since (unless it's been changed in some newer version of Arc I haven't installed yet) Arc just silently ignores the let-ing of nil: (let nil t nil) ---> nil
Re:Ask HN: Has Hacker News been hacked/cracked?
by simonb on Tuesday March 17, 2009 @04:10AM
(#519599)
But at the same time this junk variable is code-as-documentation professing the incomplete destructuring is intentional.
You could go a step further and have a special ignore symbol, (for instance * ) like most pattern matching languages/libraries have with the property that it can appear multiple times:
arc> (let (x * y . *) '(a b c d e f) y)
c