Kartik Agaram <a...@akkartik.com>
> > if
> > . {1 iso {x % 2}}
> > . \ 'odd
> > . :else
> > . \ 'even
> 
> My complaint with this is that it doesn't sufficiently distinguish
> tests from branches. Especially since 'if' in arc/wart can have more
> than two branches. It also replaces 'cond' in lisp/scheme.
> 
> I'm not entirely happy with any of the ways to format if/cond.

In a simple 2-way branch, I try to cuddle the condition right after "if" where 
possible:
. if iso(1 {x % 2})
. . 'odd
. . 'even

A traditional cond-like expression is really easy with indentation, 
modern-expressions, and curly infix:

cond
.   evenp(a) a           ;if a is even return a
.   {a > 9} {a / 2}    ;else if a is bigger than 9 return a/2
.   {a < 2} {a - 1}     ;else if a is smaller than 2 return a-1
.   #t 17

=>
(cond
   ((evenp a) a)                 ;if a is even return a
   ((> a 9) (/ a 2))    ;else if a is bigger than 9 return a/2
   ((< a 2) (- a 1))    ;else if a is smaller than 2 return a-1
   (#t 17))

If the right-hand expression is too long to cuddle on one line, just indent it 
under its condition.  No problem, and really clear.

(Sample inspired by http://www.cs.cmu.edu/~ggordon/lisp-hints.txt)


An Arc-like "if" is an interesting case. I think we're moving towards 
SPLICE-at-front as being essentially a comment.  If so, I can imagine that the 
SPLICE could be used to highlight the what-to-do while leaving it at the same 
level:
. if condition1()
. . \ do-condition1()
. . condition2()
. . \ do-condition2()
. . condition3()
. . \ do-condition3()
. . \ otherwise()

=> (if (condition1) (do-condition1)
         (condition2) (do-condition2)
         (condition3) (do-condition3)
         (otherwise))


--- 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
Readable-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/readable-discuss

Reply via email to