4 ms·
Lisp inspires some people to work at the implementation level. My TXR Lisp (http://www.nongnu.org/txr http://www.nongnu.org/txr) has strong ties to Common Lisp
by kazinator 11y ago
Lisp inspires some people to work at the implementation level.
My TXR Lisp (http://www.nongnu.org/txr http://www.nongnu.org/txr) has strong ties to Common Lisp, but it does certain things which I've been able to do easily due to working at the implementation level.
For instance, I have regular cons cells as well as lazy cons cells, both of which satisfy the consp function, and are recognized by all the library functions, from car and cdr onward. If this were develpeed in an existing Lisp, it would require rewriting the library from scratch. E.g. not using the standard car, cdr, mapcar and so on.
Another example is that forms can optionally express Lisp-1 style evaluation for those arguments which are symbols. This is sugared over with square brackets.
;; list is in the function namespace, but resolved
[mapcar list whatever]
Implementing this correctly means writing your own code walker; it's not just "add a macro and hand off the code to Lisp's evaluator/compiler". The exact rule is that the closest lexical binding of the identifier is used, whether it is a function or variable; and if there is no lexical binding, then the global one is used. If both a function and variable of the same name exist globally, then preference is given to the variable binding. It doesn't end there: symbol macros have to be handled properly: in [a b], a or b or both could be symbol macros. But they get shadowed by function bindings which are lexically inner:
(defsymacro ((m whatever))
(flet ((m () ...))
(m ...) ;; unambiguously function
(list m) ;; expanded as symbol macro
[m ... m ...])) ;; function everywhere
Lisp has always been a family of languages. From almost the very beginning, there were numerous dialects. Every major institution that had Lisp activity had its own dialect!
It is in recognition of this that the late John MacCarthy expressed his wish that no dialect be just called "Lisp".
Forty years ago you could have said, "if Lisp is go great, why do we have MacLisp, InterLisp, BBN Lisp, ..."
Part of the reason Lisp is great is that it teaches programmers to fish.
- klibertp 11y agoHi, I just wanted to tell you that I'm learning TXR right now (https://klibert.pl/output/this_week_on_polyglot.html https://klibert.pl/output/this_week_on_polyglot.html) and I like it very much. My current goal is to write a tutorial for it: the docs are good and pretty detailed, but they aren't exactly friendly to new users. I hope I'll manage to finish this, I think TXR deserves much wider recognition. Anyway, thanks for your work on TXR and thanks for making it available. Great job!
- kazinator 11y agoHi. I think your code snippet: @ (block cd) @ (bind v @(get-string (open-command `cd @path && git remote -v`))) @ (next :string `@v`) @ (skip) vps@a(fetch) @ (bind url @(trim-str a)) @ (end) probably just wants to be something like perhaps this: @(next `!cd @path && git remote -v`) vps@\t@url (fetch) Match directly into the output of the git command with @(next ...), and extract the url directly: it is delimited by tab from the remote name (which we can use literally or represent using @\t) and by a space from the (fetch) or (push) keyword. Thus we can eliminate the trim-str extra step and variable. Also if v holds a string, `@v` simplifies to v! Another thing is that if we are just marching through data to produce output, and don't actually need to collect anything to analyze, we can convert this structure: @(collect) ...match... @(end) @(output) @ (repeat) ...spew... @ (end) @(end) into: @(repeat) ...match... @ (output) ...spew... @ (end) @(end) It's not just shorter, but efficient too if the data is large (it doesn't hang on to collected data as it marches through it). Cheers ...
- klibertp 11y agoThanks! I rewrote the example according to your suggestions. It's true that the part with @v, open-command, etc. wanted to be written differently. I realized that there has to be a better way of calling external command - I just couldn't find it then. Looking at the docs now, the meaning of ! is mentioned briefly: > The @(next) directive supports the file name conventions as the command line. The name - means standard input. Text which starts with a ! is interpreted as a shell command whose output is read like a file. These interpretations are applied after variable substitution. If the file is specified as @a, but the variable a expands to "!echo foo", then the output of the "echo foo" command will be processed. So it looks like I just missed it on my first reading.