[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] Legacy caar to cddddr



On Sat, Oct 22, 2011 at 11:46 PM, Andre van Tonder <andre@x> wrote:
> On Fri, 21 Oct 2011, Aubrey Jaffer wrote:
>
>> | I've used those procedures myself, and *every* single time it has
>> | been a mistake.  I'd rather they go away so I'm not tempted, and am
>> | forced to properly abstract from the start.
>>
>> C*R procedures are very useful in symbolic algebra, for graphs and
>> trees, and for manipulating programs (such as compiling).  Claims of
>> their demise are premature.
>
> I agree.  I have found them useful for manipulating programs.  Once you are
> used to them, you can see at a glance what they are doing (just like with
> CAR and CDR).
>
> Here is an example of their use in a renaming-style macro (as WG2 promises
> us we will have).  Used here are CAR, CDR, CADR, CDDR, CADDR, and CDDDR.
>  All these are used in a completely obvious and transparent way.  This is
> not a "code smell".

Personally I think it is.  `cadr' is `second' and `caddr' is `third',
which makes things clearer, and `cdddr' is (list-tail ls 3) or
maybe `third-tail'.  Any of the 6 remaining depth-3 accessors
are just obfuscation.  Likewise beyond `fourth' and `fourth-tail',
the 14 depth-4 accessors are ugly.

For parsing out macro arguments I prefer pattern matching,
(`match' works great with ER macros) which is visually clearer
and allows for better error messages.  If you do want to do
it manually, though, mostly you're just pulling out positional
arguments, and you can validate in advance by checking
the length.  If you have nested destructuring on terms and
don't want to use pattern matching, you should at least
abstract your code and not sprinkle it with cdaadr and the
like.

I'm not going to push hard on this though - it's probably too
late in the game to change.  And as I said initially and John
reiterated, we'd at most just be moving these to a separate
library, to trim down (scheme base), not getting rid of them.
But I'd be happy to continue debating :)

-- 
Alex

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports