libera/commonlisp - IRC Chatlog
Search
3:26:42
Bike
the resumptive quality is critical to how lisp conditions work and it's not common in other languages. if you don't allow handlers to resume, your implementation can just unconditionally jump up the stack frames and there ya go.
3:48:08
nij-
But Bike was answering "nij- > Why do we need first class functions?" which might be hard to answer though..
3:51:34
nij-
But I'm aware it's not always an easy task.. I often found it hard to explain something I know well too :(
3:57:19
beach
The point, though, is that when you design a language, you should include the low-level primitives that allow you to build powerful, yet simple, high-level mechanisms.
4:04:52
Bike
the basic nature of exceptions or conditions or whatever is that you have a function F call a function G, and G transfers control to F in some way other than returning normally.
4:05:26
Bike
in most languages that's one way: G does an abnormal exit and you're back in a "handler" in F. but in lisp the handler can decide G is actually doing fine, and control can resume in G somewhere.
4:06:12
Bike
because of this, it has to be possible for the handler code to run without permanently exiting G.
4:06:37
Bike
the simple way to do this, which implementations generally do, is to have the handler be a first class function that the signaling code in G just calls normally.
4:10:52
nij-
It makes more sense! Thank you, Bike. However, why can't the handler be a non-first class function? After all, the signaling code G can call a non-first-class function.
4:14:21
beach
nij-: If it is not a first-class function, it would have to be invoked by name, like (handler ...), but the name is not known statically.
4:15:18
beach
nij-: The handler must be looked up in the dynamic environment, i.e., the call stack. And then, it must be possible to manipulated like any other value, like (funcall (find-handler ...) ...) which requires a first-class function.
4:16:43
beach
nij-: An entity that is first class is one that can be the value of a variable, can be passed as the argument to a function, and can be returned as the value of a function call.
4:18:57
nij-
That's what I understand. Ah I see.. otherwise you need to refer by name which is not so convenient.
4:20:18
nij-
--- Is there a bug in the examples of this CLHS page? http://www.lispworks.com/documentation/lw70/CLHS/Body/f_invo_1.htm
5:02:49
beach
nij-: The examples have several problems. They are not normative, so I suspect they were not as well scrutinized as the normative parts.
8:35:43
Shinmera
jackdaniel: Does ECL have any functions to convert floats to/from their bit/integer versions? Asking since float-features lacks support for those conversion functions under ECL at the moment.
9:04:08
rendar
i'm creating a little lisp interpreter in python, which supports coroutines and async computation. I was thinking, if i have a function which needs the results of 2 websites, e.g. `(my_fn (get_url a.com) (get_url b.com))` i could run those 2 get_urls function concurrently, in the underlying python.. is this concurrently running a thing in modern lisp?
9:06:42
hayley
The lparallel library would let you do something like (parallel-let ((x (get-url "a.com")) (y (get-url "b.com"))) (use x y)) which is longer, but makes explicit what runs concurrently. _Could_ you run get-url concurrently in your language semantics?
9:07:55
rendar
now, i think i have to explicitly differentiate the function that can return immediately, and the functions that must be awaited, such as get_url
9:09:37
hayley
Perhaps not for get-url specifically, but can't arguments to a function be mutable, and you'd thus have shared state if I did e.g. (let ((x (make-something))) (concurrently (f x) (f x)))?
9:12:42
rendar
it will fire 2 http requests, and will process one when one finished, but that's all happening into one thread, those are coroutines..
9:14:10
hayley
I use Leslie Lamport's definition of "concurrency", where two things happen "concurrently" if one does not strictly occur before or after the other. If one is only processed when the other finished, those tasks do not appear concurrent.
9:15:56
rendar
just work is fired concurrently, and results are grasped concurrently, but everything is happening into 1 single thread
9:18:09
hayley
The issue with shared state is one involving concurrency, not if the tasks actually run in parallel or not.
9:18:53
hayley
(The latter, still, is useful on multi-core computers i.e. most of them, but this is an interpreter written in Python, so, yeah.)
9:19:23
rendar
hayley, well, that 'x' in your example of before could be read/write before/after of one of the get_url() depending on the website time response, for instance
9:21:42
hayley
I'd prefer to make introducing concurrency an explicit operation, because someone reading a program needs to be quite careful about how they reason about it.
9:22:40
rendar
hayley, so you would like more something like this (my_fn (concur (get_url a) (get_url b)))
9:26:31
hayley
The example with parallel-let I gave before would work, but is quite verbose. In the general case of "retrieving multiple pages concurrently", which I've done before, a parallel mapping function i.e. (parallel-map #'get-url urls) is common.
9:32:28
jackdaniel
Shinmera: I'm not aware of such a function. do you mean something like this? http://turtleware.eu/static/paste/40e87d6f-foo.lisp
9:33:50
Shinmera
Essentially this stuff https://github.com/Shinmera/float-features/blob/master/float-features.lisp#L271-L500
9:33:51
jackdaniel
(this won't work with bytecodes compiler; we could probably incorporate it into the core though - what are function names in sbcl and ccl? [for compatibility])
9:44:59
jackdaniel
hm, this is somewhat troublesome, but is there no portable C integer type to hold long double? :)
10:24:11
jackdaniel
first you need to know how many bits there is, otherwise you will add garbage to the result
10:25:39
jackdaniel
in principle this could be done the same as with the constant si:cl-fixnum-bits (that is - fill it when ecl is built); oh well, I'll add single and double and signal an error for long float for now (but api-wise it will be covered!)
10:34:28
jackdaniel
shouldn't they be handled the same as single float? (I don't think that there is an implementation implementing them as half-precision)
11:19:21
rendar
can we say that everything in CL is represented (in C, for instance) by `struct Cons { elem * car; elem * cdr; };` ?
11:20:26
rendar
the book i'm reading speaks about the LIST function which fills the car pointers and the cdr pointers, so i have imagined something like that
11:21:05
jackdaniel
rendar: how will you represent a number 42 as struct Cons { elem * car; elem * cdr; }; ?
11:21:10
hayley
A cons cell can be represented like your description, but not everything is a cons cell.
11:21:50
rendar
jackdaniel, well, that is the "elem" the Cons struct points to, so 42 is an elem, and (42) is cons.car->42,cdr->nil
11:22:24
jackdaniel
but you said, that everything is represented as that struct; is it that integer does not fall in the category "everything"?
11:25:55
jackdaniel
Shinmera: https://gitlab.com/embeddable-common-lisp/ecl/-/commit/1ce4713804e704dd29a1c56bfabe3ea5a129a0f5?view=inline
11:29:16
Shinmera
jackdaniel: very nice. now the only question left is: how do I make the library not completely break on older ECL versions
11:30:36
jackdaniel
(when (find-symbol "BITS-SINGLE-FLOAT" "SYSTEM") (push 'float-features::ecl-can-do-this *features*)) ;comes to mind
11:32:12
jackdaniel
there is also ext:+ecl-version-number+ for checking (a monotonic version number)
11:34:45
_death
rendar: as an optimization some objects (say fixnums or characters) may be stored in place of the pointer.. also, while lisp has a cons/atom dichotomy, the atoms may be aggregates (think arrays)
11:55:02
yitzi
Shinmera: do you know where the LispWorks version reader macro is documented? Please don't look if you don't, I can find if you don't know right off of the top of your head.
11:55:29
Shinmera
But I remember seeing it in library code and missing it on other implementations ever since
12:28:28
Shinmera
Ooh. Just got an automated quicklisp issue ticket. Maybe a new dist release is going to appear soon :)