|
|
|
|
|
by sedachv
3039 days ago
|
|
Any time people claim that Lisp is a functional programming language, I like to drag out this example posted by Joe Marshall to comp.lang.lisp[1]: (DEFUN RDSYL (L DF)
(PROG (LL BRAKP ANS CH)
(SETQ DF (MERGEF DF '((* *) * *)))
AA (SETQ LL (SETQ BRAKP () ))
A (SETQ CH (OR (CAR L) #/_))
(COND ((OR (= CH #/ ) (= CH #//)) ;"/", " "
(POP L)
(SETQ CH (CAR L)))
((AND (= CH #/[) (NOT #%(ITSP))) ;"["
(SETQ BRAKP 'T))
((AND (= CH #/]) (NOT #%(ITSP))) (SETQ BRAKP () )) ;"]"
((OR (= CH #/( ) (= CH #/) )) (RETURN () )) ;Cant have parens here
((= CH #/,) ;Comma
(COND ((NOT BRAKP)
(POP L)
(GO RET))))
((= CH #/_) (GO RET)))
(PUSH CH LL)
(POP L)
(GO A)
RET (SETQ DF (MERGEF (NAMELIST (MAKNAM (NREVERSE LL))) DF))
(SETQ ANS (NCONC ANS (LIST DF)))
(AND (= CH #/,) (GO AA))
(RETURN ANS) ))
There is a lot of this kind of code around in the various Lisp Machine sources (CADR is legally available for poking around in[2]). Occasionally things like this pop up in contemporary Lisp compilers or IO/concurrency libraries. Some algorithms are much easier to express with goto.[1] https://groups.google.com/forum/#!msg/comp.lang.lisp/4nwskBo... [2] http://www.unlambda.com/cadr/ |
|