Re:Lisp and Haskell (2017)
by kazinator on Sunday July 15, 2018 @01:05AM
(#17533877)
Log of my last 3 minutes of activity:
This is the TXR Lisp interactive listener of TXR 197.
Quit with :quit or Ctrl-D on empty line. Ctrl-X ? for cheatsheet.
1> (defun add-text-padding (str nspaces : newline-p)
(let ((padding `\n@(mkstring nspaces)`))
(when newline-p
(set str `\n@str`))
(regsub #/\n/ padding str)))
add-text-padding
2> (add-text-padding "hello\nworld")
** (expr-2:1) add-text-padding: too few arguments
3> (add-text-padding "hello\nworld" 3)
"hello\n world"
4> (add-text-padding "hello\nworld" 3 t)
"\n hello\n world"
Note how (mkstring n) makes a string of n spaces by default; if you want a different character, specify it as a second argument.
I've never heard of trivial-update, but TXR has something like it built-in that I independently invented called upd:
1> (defvar a 0)
a
2> (upd a (+ 2) (* 3))
6
3> a
6
upd implicitly uses the syntax of the partial application operator op to create a pipeline of partial applications. To get such a pipeline by itself as a function, opip can be used; upd is simply the result of wanting a place-mutating operator that takes a place's value through an opip pipe and then writes the result back in.
TXR Lisp also has a well-featured command line option parsing library built-in:
I've never heard of trivial-update, but TXR has something like it built-in that I independently invented called upd:
upd implicitly uses the syntax of the partial application operator op to create a pipeline of partial applications. To get such a pipeline by itself as a function, opip can be used; upd is simply the result of wanting a place-mutating operator that takes a place's value through an opip pipe and then writes the result back in.TXR Lisp also has a well-featured command line option parsing library built-in:
http://nongnu.org/txr/txr-manpage.html#N-02C70C38