libera/commonlisp - IRC Chatlog
Search
12:23:56
nij-
It suggests that such lack is a drawback, making wonder if they were functions (ofc they cant be).. what would be different?
12:24:29
beach
nij-: I don't have in memory what he meant, but I am guessing that he meant something like how (SETF MACRO-FUNCTION) and MACRO-FUNCTION are the functional interface for macros.
12:25:27
hayley
I think phoe mentioned a lack of "introspection" functions for handlers in his OLM presentation.
12:26:38
nij-
4. (phoe) Are there any ready-to-use portable condition system that's based on CLOS ;) ?
12:26:55
beach
nij-: Sometimes, the standard specifies an underlying function interface to macros, like DEFUN is defined in terms of FDEFINITION and (SETF FDEFINITION). Sometimes it doesn't, like DEFTYPE does not have an underlying interface using functions.
12:28:31
nij-
Yeah I think what phoe meant in his book is that the standard one is not based on CLOS. And unfortunately in at least one popular implementation it's really not based on CLOS.
12:28:54
hayley
Bindings for restarts and handlers have dynamic extent still. Would one have, say, a CALL-WITH-RESTARTS function as a functional analog to RESTART-CASE?
12:30:45
beach
nij-: That might be for historical reasons and because of the way bootstrapping is done in must existing Common Lisp implementations.
12:31:17
nij-
beach I mean has someone written a portable condition system for Lisp that's based on CLOS
12:31:50
beach
nij-: I just don't know what "based on" means. Whether it somehow exposes CLOS to the user of it, or whether it is just implemented using it.
12:32:36
beach
nij-: In most Common Lisp implementations, CLOS is "bolted on" at the end. So if they want the condition system to work before that, they can't use CLOS to implement it.
12:33:57
hayley
(I remember I made a lazy attempt at updating Pitman's code before, but got bored of it quickly.)
12:34:56
jackdaniel
I don't know how about other implementations, but in ecl define-condition is defclass under the hood
12:35:29
jackdaniel
and make-condition is make-instance (after processing arguments to have the proper shape)
12:35:35
nij-
jackdaniel yeah I think he mentioned that most impls uses CLOS, but at least one popular impl doesnt
12:35:55
beach
nij-: The system written by phoe is basically what SICL uses natively. I made a few changes.
12:36:48
beach
nij-: What phoe wrote was not meant to be used natively, so I had to adapt it in a few ways.
12:38:21
beach
nij-: The point here is that the Common Lisp condition system is very simple. Once you have non-local control transfer in the form of CATCH/THROW, TAGBODY/GO, and BLOCK/RETURN-FROM, and macros, then you can write a complete condition system.
12:39:15
beach
nij-: This is why phoe has been arguing in favor of non-local control transfer in WASM. As opposed to including a complicated exception system in the language itself.
12:39:40
nij-
And is it correct to say that if one implements handler-bind, then all other relevant operators in C-S can be impl easily?
12:41:16
hayley
Note that due to https://www.plover.com/~mjd/misc/hbaker-archive/MetaCircular.html only one sort of non-local control transfer is necessary to produce the other two.
12:44:25
jackdaniel
re wasm, some changes are not introduced to it because of the current "stake holders" say that this would require too much work on their end;
12:45:11
jackdaniel
that said there is hope if microwasm is adopted (some runtimes already implement it), because it provides better primitives i.e to implement non-local control transfer
12:46:14
nij-
But this page gets me lost.. http://clhs.lisp.se/Body/d_specia.htm#special I'm no longer sure if that's merely the case.
12:46:53
dim
hi there! is Xach still around sometimes? The certificate for www.xach.com expired on 6/15/2022
12:53:36
pjb
_death: I explained that a predicate makes less sense than a list, because to collect the list, you need to do more work, and the predicate already knows the list! It's not like it was a property of the symbol, it's just an arbitrary set.
12:54:55
pjb
nij-: the point is that macro functions are functions like any other, there's no predicate to distinguish them. This is due to the fact, that there's no operator to get a function signature. Any function that takes a form (a proper list), and an environment can be used as a macro-function!
12:57:13
pjb
_death: we mentionned the need of a grammar for the additionnal keywords. sicl uses a parser that allows adding custom grammar rules for lambda-lists.
12:58:21
pjb
nij-: (mapcar (macro-function 'and) '((and t t) (and nil t) (and t nil) (and nil nil)) '(nil nil nil nil)) #| --> ((if t (and t)) (if nil (and t)) (if t (and nil)) (if nil (and nil))) |#
12:59:17
pjb
nij-: (mapcar (alexandria:compose #'eval (macro-function 'and)) '((and t t) (and nil t) (and t nil) (and nil nil)) '(nil nil nil nil)) #| --> (t nil nil nil) |# DUH!
15:24:27
jackdaniel
I'm playing with serializing and expanding protocols to code, here's McCLIM geometry substrate with extensions (the svg document is generated with McCLIM): http://turtleware.eu/static/paste/c5c3e822-proto.svg
16:09:32
jackdaniel
I'm working on separating a low-level hardware access abstractions (similar to Silica from Genera) as a separate system "silex", so it will be reusable as a portable lisp base for any kind of toolkits
16:10:15
jackdaniel
(from the mcclim perspective nothing will change, but loading this system alone won't pull numerous clim abstractions)
18:00:22
contrapunctus
Good, so I don't have to copy-paste my NIH version of that in all my projects ^^'
18:18:14
contrapunctus
White_Flame: heh. When I was about to copy-paste it into a third project, I realized that there _had_ to be something for this in some util library somewhere.
19:38:20
dlowe
fourier: checking for it in initialize-instance seems to be a reasonable choice, though you might want to check for it in reinitialize-instance too
19:56:05
Krystof
I'm missing context, but if this is about an initarg check for a standard object, you might want to do it in shared-initialize
19:56:27
Krystof
(which will catch initialization, reinitialization, change-class and class redefinition)
20:44:12
dlowe
so the context is making sure a class-slot is initialized to something passed into make-instance
21:13:57
pjb
rendar: in smalltalk a message is: object message: arg1 msg: arg2 . to send a message named message:msg: with arg1 and arg2 to object.
21:14:30
pjb
rendar: The syntax for blocks (lambda): [ parameters | local variables | messages … ^ result ]
21:14:57
pjb
often in the code, we use thunks, ie. lambda without parameters: [ | local variables | … ]
21:16:14
pjb
rendar: now, I implemented a reader macro similar to Objective-C for Common Lisp : Objective-CL
21:16:46
pjb
rendar: https://gitlab.com/com-informatimago/com-informatimago/-/blob/master/objcl/documentation.pdf
21:17:53
pjb
rendar: it would need an overhaul to be able to work with all the Objective-C runtime via all the FFI (ie. CFFI) on all the CL implementations. For now, it works mostly with the Apple runtime on CCL (and CFFI but also some CCL specific FFI).
21:18:29
rendar
i'm interesting in deep understanding the differences between smalltalk/objc blocks vs. s-expressions
21:18:36
pjb
This files gives some examples: https://gitlab.com/com-informatimago/com-informatimago/-/blob/master/objcl/howto.lisp
21:19:49
pjb
We can use such literal lisp data to represent programs: (if (= a b) (princ "equal") (princ "different"))
21:20:39
pjb
We can write programs called interpreters or compilers, to evaluate such programs. There's CL:EVAL, CL:COMPILE, and CL:COERCE that can convert S-expressions representing programs into lisp execution or compiled lisp functions.
21:21:09
pjb
To represent a function we use the data syntax: (lambda (a b) (if (= a b) (princ "equal") (princ "different")))
21:21:24
pjb
And we can compile it: (compile nil (quote (lambda (a b) (if (= a b) (princ "equal") (princ "different"))))) #| --> #<Anonymous Function #x302008B990DF> ; nil ; nil |#
21:21:41
pjb
We can then call this function: (let ((fun (compile nil (quote (lambda (a b) (if (= a b) (princ "equal") (princ "different"))))))) (funcall fun 1 2)) #| different --> "different" |#
21:22:13
pjb
Here the s-expression is a literal (as denoted by the quote operator); but you can also build it with your own programs.
21:22:27
pjb
Oh! Note that the program (let ((fun (compile nil (quote (lambda (a b) (if (= a b) (princ "equal") (princ "different"))))))) (funcall fun 1 2)) is also a S-expression!!!
21:23:28
pjb
This works because the lisp system contains a REPL and a file compiler and file loader that will read those S-expressions, and pass them to CL:EVAL automatically: (LOAD "file.lisp") or (COMPILE-FILE "file.lisp"), or the REPL.
21:23:46
pjb
the REPL is a Read Eval Print Loop that is the basis of interaction with the lisp system.
21:24:15
pjb
When you type a S-expression in the REPL, it is first READ, ie the text you type is converted to a lisp data structure (a list if it starts with "(").
21:24:42
pjb
THen this lisp data structure is passed to CL:EVAL which will interpret it, and return the result. The result is passed to PRINT which prints it.
21:26:05
pjb
rendar: Smalltalk blocks are like lisp anonymous functions. They can be written in S-expression as: (lambda (parameters…) (let ((local) (variables) …) body expressions result))
21:26:49
pjb
So you can write (defmethod ifThen ((test T #| generalized boolean |#) thunk) (if test (funcall thunk)))
21:28:09
pjb
and since we represent lisp program sources as lisp data, you can use S-expressions to write all lisp programs.
21:28:57
pjb
In almost all other languages, the source is defined as a text file, ie a string of characters.
21:29:26
pjb
But in lisp, the source is lisp data (cons cells, atoms, numbers, strings, etc). This is what is processed by EVAL or COMPILE.
21:29:45
pjb
Only this lisp data can be read with CL:READ, from the S-expression form (which is also a textual representation).
21:30:13
pjb
And since there's also a printer CL:PRINT to print S-expressions, we can print and read and print back code (or data).
21:31:14
pjb
Now, there are some types of lisp objects that don't have a readable print syntax. Eg. packages: *package* #| --> #<Package "COMMON-LISP-USER"> |# It starts with #< which cannot be read.
21:32:36
pjb
But for you own classes of objects, you can define a method on the PRINT-OBJECT generic function to print them readably.
21:33:07
pjb
For example, CCL does this for random states: *random-state* #| --> #.(ccl::initialize-mrg31k3p-state 1662898282 955392070 420261365 823417203 431141722 953184299) |# It uses the #. syntax which reads a form and evaluates to read the object.
21:34:02
pjb
rendar: yes, and no. The thing is that the grammar is trivial. There's a lexical analysis which is specified in the chapter 2 of CLHS, as the "lisp reader algorith", and all the rest of the syntax is defined as reader macros and dispatching reader macros.
21:34:30
pjb
The lisp reader algorithm knows only how to read symbols, integers, ratio and floating point numbers.
21:35:53
pjb
We can give a coarse grammar for S-expr, but this is only what lisp does by default, with the default reader macros. You can install your own reader macros, and change that syntax.
21:36:23
pjb
rendar: AFAIK nope. There's a copyright on the web site. IIRC gcl had the authorization to make a copy in info format.
21:37:10
pjb
rendar: the ANSI/ISO organization will sell you for dear money a PDF of the standard, which is a bad scanning of a paper printout. It's not worth paying for it, unless you need it for legal reasons.
21:38:19
pjb
atom ::= integer | ratio | float | string | structure | … . all literal lisp object syntaxes specified by the reader macros.
21:38:56
pjb
rendar: I like ccl. sbcl is liked by a lot of people because it generate fast code, but it has the inconvenient of having a new release each month!!!
21:39:18
pjb
rendar: abcl is nice if you want to run on the JVM. ecl is nice if you want to embed it with C applications.
21:40:03
pjb
rendar: I find clisp nice for newbies, since it contains an interpreter, and some niceties, (but a lot of people don't like it because it has new releases each 10 or 20 years, and compiles to a VM).
21:48:59
pjb
rendar: note that you may prefer to read some book or lisp tutorial before reading the CLHS, since the later is not pedagogical at all (it's a language reference).