On Sun, Aug 5, 2012 at 5:53 AM, David A. Wheeler <[email protected]> wrote:
> Alan Manuel Gloria:
>> Have some more SUBLIST abuse!!!
>>
>> Note that what I'm talking about, mostly, is: should we consider this
>> good style or bad style?  If bad, what's a better expression of the
>> same logic?
>>
>> ; please view using a fixed-width font!
>> define map1(f as) $ cond
>> ! null?(as) $ '()
>> ! pair?(as) $ cons
>> !               f $ car as
>> !               map f $ cdr as
>> ! #t        $ error "attempt to map a non-list"
>
> Interesting question.

The main reason why the above is attractive to me (despite the cond
hiding there) is because it looks and feels a whole lot like
Haskellian:

map1 f as
 | null as = []
 | pair as = (:)
         (f $ car as)
         (map f $ cdr as)
 | otherwise = error "attempt to map a non-list"

>
> Currently I've been using the following two formats for cond's pairs of 
> condition/action:
>
> 1. When result is short:
> ! condition-as-neoteric action-as-neoteric
>
> 2. When result is long:
> ! condition-as-neoteric
> ! ! action-as-sweet
>
> And as I mentioned before, I prefer to put on the LHS any atom that's a 
> control structure UNLESS the whole structure fits in the line.
>
> So I would do:
> define map1(f as)
> ! cond
> ! ! null?(as) $ '()
> ! ! pair?(as)
> ! ! ! cons
> ! ! ! ! f ar as
> ! ! ! ! map f cdr(as)
> ! ! #t error("attempt to map a non-list")
>
>
> Your use of "$" everywhere to connect condition and action looks like this:
> ! condition-as-neoteric $ action-as-sweet
>
> This is an interesting use of "$", and it means that in actions you can drop 
> some parens (which has its advantages).  However, it means that you have to 
> use neoteric on the left, even though you can (and probably would) use sweet 
> on the right.   That seems possibly-inconsistent to me.
>
> If that's a common case, perhaps in spec version 0.4 we should take:
>   left-hand-side-on-same-line $ right-hand-side-with-subblocks
> and redefine it as:
> \\
> ! \\ left-hand-side-on-same-line
> ! \\ right-hand-side-with-subblocks

bleah.  I much prefer to be able to use "map f $ cdr as" than "pred? x
$ foo bar".

Personally, I think that it's generally better to have shorter
predicate code (stuff that's easy to express in n-expr) and a longer
condition.

>
> Then you could say sweet-expressions on both sides, e.g.:
> ! null? as $ '()
>
> And you could use leading "$" to take the right-hand-side and put it into a 
> list.
>
> HOWEVER, that would also means that "map f $ cdr as" would no longer have the 
> current meaning, and there wouldn't be a way using "$" to express that.  
> Granted, in this case "map f cdr(as)" is at least as simple.
>
> It's a trade-off; without code samples it's hard for me to say which way is 
> the best trade.  Hopefully the experience we gain now will make it obvious.
>
> --- David A. Wheeler

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Readable-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/readable-discuss

Reply via email to