47 ms·
Being able to write new control structures is something I miss in most languages. Lisp macros make it much easier to do that. Tcl uplevel and upvar are another
by RHSeeger 7y ago
Being able to write new control structures is something I miss in most languages. Lisp macros make it much easier to do that. Tcl uplevel and upvar are another way to approach it.
- LessDmesg 7y agoCurious: what kind of new control structures do you miss in other languages?
- bjoli 7y agoDelimited gotos. Many lacks proper looping constructs. CL has a package a macro that gives you a limited version delimited continuations which are handy for some situations.
- RHSeeger 7y agoA good example would be a case switch, that ran the first block that evaluated to true (lisp has this, many languages don't). That being said, custom control structures can abstract away some things.
- stevelosh 7y agoThis would save me literally thousands of lines of code at my day job: (defmacro ?= (symbol-or-symbols expr) (let* ((symbols (etypecase symbol-or-symbols (cons symbol-or-symbols) (symbol (list symbol-or-symbols)))) (tmps (loop :for s :in symbols :collect (gensym (symbol-name s)))) (err (gensym "ERROR"))) `(multiple-value-bind (,@tmps ,err) ,expr (if (not (null ,err)) (return ,err) (setf (values ,@symbols) (values ,@tmps))))))