Neil had an example upthread. Robby
On Thu, Nov 11, 2010 at 12:36 PM, Carl Eastlund <c...@ccs.neu.edu> wrote: > On Thu, Nov 11, 2010 at 1:29 PM, Eli Barzilay <e...@barzilay.org> wrote: >> Two minutes ago, Carl Eastlund wrote: >>> On Thu, Nov 11, 2010 at 1:21 PM, Eli Barzilay <e...@barzilay.org> wrote: >>> > About a minute ago, Carl Eastlund wrote: >>> >> On Thu, Nov 11, 2010 at 1:14 PM, Eli Barzilay <e...@barzilay.org> wrote: >>> >> >> I got inspired by the #:when form in `for' loops that flattens >>> >> >> nesting, and wrote a `cond*' macro that allows this instead: >>> >> >> >>> >> >> (cond* [... some stuff ...] >>> >> >> #:with (define m ...) >>> >> >> [(... something about m ...) (... something using m ...)] >>> >> >> ... more things referring to m ...) >>> >> >> >>> >> >> It's more general, since it doesn't require encoding the condition >>> >> >> you want to test as a truthiness value. Also, the `define' doesn't >>> >> >> have to be a `define' - it can be any legal expression. >>> >> > >>> >> > So, you advocate eliminating `member' etc for predicates (why I >>> >> > started with saying that this is much stickier than just adding a >>> >> > `member?'). So we started with >>> >> > >>> >> > (cdr (assq x alist)) >>> >> > >>> >> > then Scheme upgraded this to >>> >> > >>> >> > (cond [(assq x alist) => cdr] >>> >> > [else #f]) >>> >> > >>> >> > and you suggest continuing with >>> >> > >>> >> > (cond #:with (define p (assq x alist)) >>> >> > [(pair? p) (cdr p)] >>> >> > [else #f]) >>> >> > >>> >> > or, with more well-behaved proper sub lists >>> >> > >>> >> > (cond #:with (define p (assq x alist)) >>> >> > [(not (eq? p #f)) (cadr p)] >>> >> > [else #f]) >>> >> > >>> >> > (Yes, you can still use `pair?' but that would be ugly for the same >>> >> > reason.) >>> >> > >>> >> > I also wonder how many newbies (or people that just want to type less) >>> >> > will fall into traps like >>> >> > >>> >> > (if (member? x l) >>> >> > (+ 1 (find x l)) >>> >> > 0) >>> >> > >>> >> > My loud "ugh" should be expected now. >>> >> >>> >> (dict-ref x alist) >>> > >>> > The above is "an example", substitute appropriately. >>> >>> As is mine. We have a dict library, a sequence library, and loop >>> comprehensions for a reason. Code doing any kind of key/value lookup >>> should not have to use cond, car, or cdr to do so. >> >> Either that's a nonsensical argument, or all programmers should now >> quit because everything is done. (In other words, lookups are not the >> only use of conditionals. Proof left as an exercise to the bored >> reader.) > > Is this about conditionals or lookups? You started with (cdr (assq x > alist)), and I don't see the conditional in that. > > I'm not saying programmers should quit using conditionals, I'm saying > they should quit using conditionals for everyday dictionary lookups, > so our measuring stick for conditional syntax should not be how > verbose it makes everyday dictionary lookups. I don't see how your > original point applies to more esoteric uses of conditionals, because > they never had a (cdr (assq x alist)) form. > > --Carl > _________________________________________________ > For list-related administrative tasks: > http://lists.racket-lang.org/listinfo/users > _________________________________________________ For list-related administrative tasks: http://lists.racket-lang.org/listinfo/users