zlacker

[return to "Please tell us what features you'd like in news.ycombinator"]
1. vegash+0i[view] [source] 2007-02-28 06:43:38
>>pg+(OP)
Better display of source code in comments
◧◩
2. pg+Dq8[view] [source] 2007-07-06 14:54:00
>>vegash+0i
You can now include code in comments:

 (def codetree (file)
   (trav + 1 (readall (infile file))))
Anything that appears after two newlines and a blank space is treated as code, till there's a line that doesn't begin with a space. This is like the markdown convention, but you don't have to use four spaces; one will do.

Incidentally, the code above tells me the number of nodes in the code tree of a file. Not just leaves, which would be

 (len (flat (readall (infile file))))
but interior nodes as well. To me this is the best measure of how long a program is. I used to go by lines of code

 (def codelines (file)
   (w/infile in file 
     (summing test
       (whilet line (readline in)
         (test (aand (find nonwhite line) (isnt it #\;)))))))
but I found this was encouraging me to do the wrong things.

(This kind of test matters because I'm constantly trying to make news.yc shorter as a way of pushing functionality down into Arc.)

Here's trav, btw:

 (def trav (f base tree)
   (if (atom tree)
       (base tree)
       (f (trav f base (car tree)) (trav f base (cdr tree)))))
It traverses a tree, doing something at every node. So e.g. CL copy-tree would be

 (def copy-tree (tree) (trav cons (fn (x) x) tree))
If you're wondering how the second argument to trav in codetree could be 1, it's because a constant when called as a function simply returns itself. This turns out to be quite handy.

◧◩◪
3. Zak+qs8[view] [source] 2007-07-07 01:43:37
>>pg+Dq8
Looking at the expression

 (isnt it #\;)
I'm assuming "it" is an implicit variable meaning the result of the last expression. I'm also assuming since you have "isnt" you also have "is" and it's used like this:

 (when (and (regex-match "[0-9]" foo) (is it 4))
    (print "it is 4"))
Does boundp exist in Arc, or are unset variables null? I've always thought making them null would make code shorter, though it might cause more problems than it's worth.
◧◩◪◨
4. pg+Gs8[view] [source] 2007-07-07 03:28:56
>>Zak+qs8
is is just CL eq (or rather eql)

Unset variables are not null; that would lead to horrible bugs. But I don't think boundp exists either. So far I haven't needed it.

◧◩◪◨⬒
5. Zak+Js8[view] [source] 2007-07-07 04:05:51
>>pg+Gs8
Since I haven't used a language where unset variables are null or tried to design one, I'll assume you're right. I haven't had to use boundp much in Lisp, but I've had to use its equivalents in other languages quite a bit when working on other people's code for money. I suspect that boundp showing up in code a lot is a sign of badness - most likely in the choice of variable scope. I'm not sure if leaving it out will encourage people to write better code or just write their own workarounds.

Edit: aand binding test results to "it" reminds me of Apple's Hypercard. I will read the entire thread carefully before asking questions next time.

[go to top]