12 ms·
There is something I saw on the wild here https://github.com/Shinmera/legit/blob/master/repository.lisp#L49-L56 https://github.com/Shinmera/legit/blob/master/re
by TurboHaskal 4y ago
There is something I saw on the wild here https://github.com/Shinmera/legit/blob/master/repository.lisp#L49-L56 https://github.com/Shinmera/legit/blob/master/repository.lis... which I thought was pretty cool.
We all know about memoize, but let's say I want to define a global hash-map, where the keys are actual pieces of code and the value the result that would be evaluated when executed. Something like this:
| Key | Value |
|----------------------------+--------------------------------|
| "hello" | "hello" |
| (square 5) | 25 |
| (factorial 5) | 120 |
| (git-tags "~/foo") | (list "1.0.0" "0.1.0" "0.0.1") |
| (make-instance 'singleton) | #<SINGLETON {1301DE5A03}> |
Which can then be used like this in a trivial way, just passing code because code is data:
(let ((path "~/foo")
(tags (cache `(git-tags ,path))))
(format t "Tags of ~a~% ~{- ~a~%~}"
path tags))
Sure, something like this is possible in other languages, but having done macros in languages such as Rust and Nim, it involves such a verbose and syntax soupy way of dealing with the AST that I don't feel like reaching for those abstractions that often. I'd rather just write boring code, and most consider this a feature.
- cb321 4y agoNim has `quote do:` with a kind of ghetto quasiquoting as well as genAST (and other things) to lessen the burden, but it is always simpler to write boring code (and better unless you have a burning need for The Fancy). One way to rephrase objections to "all those parens" of Lisp is that the most common style of using it makes it necessary to "write boring code 'in AST'", if you will, and not even in a very nice, commonly accepted 2-dimensional tree notation. I always wonder how different the history of prog.langs would be if early on one of the many indent/offside rule based 2-D notations had become popular with "boring code" writers in Lisp and not eschewed by "fancy macro writers" in Lisp.
- LanternLight83 4y ago> I always wonder how different the history of prog.langs would be if early on one of the many indent/offside rule based 2-D notations had become popular with "boring code" writers in Lisp and not eschewed by "fancy macro writers" in Lisp. That sounds interesting but is hard to search for, have you got an example?
- cb321 4y agoThis is the latest for Scheme according to Wikipedia's Offside Rule article [1]: http://srfi.schemers.org/srfi-119/srfi-119.html I have not read this "Wisp" spec lately, but IIRC it has many back references to prior attempts..at least in the Scheme community..not sure about the common-lisp community. EDIT: To elaborate on my `quote do:`, this is a little macro to avoid doing many tedious code repetitions: macro strp(sVars: varargs[untyped]): untyped = result = newStmtList() # strip some string vars; Assume new-scope for sV in sVars: result.add(quote do: (let `sV` = `sV`.strip)) with an example call: strp sTm,sUs,sSy,sUt,sRS,sIn,sOu,mjF,mnF,swp,vsw,isw,isr,ixr,idr,nsg,msn,mrc which will expand to code like: let sTm = sTm.strip let sUs = sUs.strip ... Maybe that's one man's "syntax soup", but I don't think it's so bad. (My 3 letter idents are probably worse!) The static typing of Nim (rather than gradual typing defaults like Lisp or Cython) tends to make beginner programs less "performance cringe" (as long as they compile with `-d:release -d:lto`!). [1] https://en.wikipedia.org/wiki/Off-side_rule https://en.wikipedia.org/wiki/Off-side_rule
- TurboHaskal 4y agoThat looks pretty good honestly! As someone who loves both Lisp and Pascal, I really need to revisit Nim.
- cb321 4y agoYou sound like you are in just the right demographic to love Nim...The Forum [1] is a good place to get support. https://forum.nim-lang.org/ https://forum.nim-lang.org/