freenode/#lisp - IRC Chatlog
Search
16:13:16
cl-arthur
I'm having trouble with a macro: (defmacro tt (ht) `(,ht (k) `(gethash ,k ,,ht))), and then (macroexpand-1 '(tt lowlink)) -> (LOWLINK (K) `(GETHASH ,K ,LOWLINK)).
16:13:25
cl-arthur
But my target is to expand into e.g. (lowlink (k) `(gethash ,k lowlink)). Having trouble figuring out how to get a simple "lowlink" into the double-backquoted list.
16:21:22
jmercouris
I have been thinking, if everything is an object, symbols must be objects, right?
16:21:47
jmercouris
and if symbols are objects, do they have two slots? one for a function, and one for a variable?
16:22:08
jmercouris
if it is an implementation detail, how does it work, on an implementation? I don't care which one, just curious
16:26:09
jackdaniel
in the past symbol property lists were used more extensively and there were indeed a slot for a function and a variable
16:27:02
jackdaniel
if you have a function denoted by a particular symbol, said symbol exists in your image
16:27:47
jmercouris
let's say we have package X and package Y, both package X and package Y use symbol Z
16:30:22
jmercouris
I'm trying to understand how the implementation knows that X::Z and Y::Z point to different things, and an example of how that is implemented
16:30:48
beach
jmercouris: All the standard says is that there exist functions SYMBOL-NAME, SYMBOL-PACKAGE, SYMBOL-VALUE, etc. It doesn't say how those are found.
16:31:26
beach
jmercouris: The implementation knows that they are different because the pointer values are different.
16:32:24
beach
jmercouris: Conceptually, every Common Lisp object is manipulated indirectly using a reference.
16:32:28
jmercouris
beach: so in your hypothetical example, you're saying pointers, are you referring to actual memory addresses (in the C sense) or just some symbolic address?
16:33:43
jackdaniel
the most straightforward way to the former is to peek in the actual implementation, and for the latter is to read in the spec
16:34:01
beach
jmercouris: The standard doesn't say what a symbol is. But here is the SICL definition of it: https://github.com/robert-strandh/SICL/blob/master/Code/Package-and-symbol/symbol-defclass.lisp
16:34:28
pjb
jmercouris: perhaps you would like to read an implementation of a package system? xach did one, which I completed. You can find it at: https://github.com/informatimago/lisp/tree/master/common-lisp/lisp-reader
16:35:03
pjb
jmercouris: alternatively, you could read The Complete Idiot’s Guide to Common Lisp Packages at http://www.flownet.com/ron/packages.pdf
16:35:07
jmercouris
my real real real meta question is why we insist on saying symbol X instead of var X or function X
16:35:59
pjb
There may be several variables named by the symbol X. There may be several functions named by the symbol X.
16:36:17
jmercouris
because it seems to be a very big distinction in Common Lisp, and I kind of get why, but I always like to confirm and reinforce my knowledge
16:36:45
pjb
(let ((x 42)) (cons x (let ((x 33)) (cons x (flet ((x () pi)) (list (flet ((x () 'foo)) (function x)) (function x))))))) #| --> (42 33 #<Compiled-function x (Non-Global) #x3020024F8B9F> #<Compiled-function x (Non-Global) #x3020024FAAAF>) |#
16:36:49
_death
methodologically "essentialism" is flawed, as it leads to trilemma of assumption, circularity, or infinite regress.. so instead of asking "what is a symbol", it's better to ask about how symbols behave, what operators you can use on them, etc.
16:37:04
beach
jmercouris: It is a convention I use so that the name of the slot will not be accidentally exported or used in SLOT-VALUE.
16:37:58
jmercouris
_death: I don't know, I figured it would be better to simply ask without assuming all questions that are salient *about* symbols whether it is how they behave or what they are
16:38:25
pjb
jmercouris: for example, I could implement a common lisp computer using wool braids. You would still call them references…
16:39:42
beach
jmercouris: Phrases such as "the function LIST" are short for "the function that has as its name the symbol LIST".
16:40:31
jmercouris
beach: could one also say something like "the function that is pointed to by the symbol LIST"?
16:40:32
pjb
(setf (symbol-function 'liste) (function list)) then the function LISTE is the same as the function LIST and it has two names…
16:40:48
jmercouris
because name, does a function ever actually have a name? just because a symbol points to it?
16:40:59
beach
jmercouris: No, because the symbol might not have a slot for the function, as you saw in the SICL definition.
16:42:16
pjb
Well, all functions are anonymous in a way: they're all created with (FUNCTION (LAMBDA …)), theorically. But named functions created with defgeneric or defun have their body wrapped in a block ,fname: (setf (symbol-function 'list) (FUNCTION (LAMBDA (…) (block list …)))) is what (defun list (…) …) does.
16:43:34
pjb
So there's theorically a way to distinguish "true" anonymous functions from defun functions, but also you can write (lambda (…) (block foo …)) and consider this anonymous functions could be named foo. Or bar. Or quux. This why even named functions cannot be considered differently than anonymous functions, fbound to some symbol…
16:45:20
beach
jmercouris: In the case of SICL, SYMBOL-FUNCTION is defined like this https://github.com/robert-strandh/SICL/blob/master/Code/Environment/standard-environment-functions.lisp#L132
16:45:22
jackdaniel
it may make sense to have a "name" property which captures its initial name (for instance for introspection)
16:45:40
pjb
(defvar *answer* 42) (let ((size 42)) (write-line "42 is named size and *answer*; is that even meaningful?"))
16:49:05
_death
in Lisp, we say that symbols are first-class objects, but we don't say how these objects are represented.. they have function cells and value cells that can be accessed using symbol-function/symbol-value.. they also have a name, an optional package, an a plist associated with them
16:50:20
jmercouris
yeah, that is however an error within the book a gentle introduction to symbolic computation :D
16:51:17
jmercouris
I think he is saying that they don't have to be associated in any way, it could be an arbitrary data structure
16:52:15
jmercouris
however, _death, are you saying that calling them cells does not imply an implementation spec, and that a cell is just an abstract way of saying that this bit of data exists with a relation?
16:53:03
beach
One could mean that, but it would be a very strange use of language to say that the symbol has a function cell if there is no such slot in the symbol.
16:53:04
pjb
On the other hand, it always has a plist. That's because (defun symbol-name (s) (get s 'apname)) (defun symbol-value (s) (get s 'value)) (defun symbol-function s (s) (get s 'fexpr)) were an implementation, once upon a time.
16:53:16
jackdaniel
from the spec (symbol-function): " Accesses the symbol's function cell. "; function cell: "function cell n. Trad. (of a symbol) The place which holds the definition of the global function binding, if any, named by that symbol, and which is accessed by symbol-function. See cell. ", cell: "cell n. Trad. (of an object) a conceptual slot of that object. The dynamic variable and global function bindings of a
16:53:22
jackdaniel
symbol are sometimes referred to as its value cell and function cell, respectively. "; so traditionally speaking Gentle is not wrong ;)
16:54:36
pjb
It's understood that those cells are "virtual" or abstract cells. Even CLOS instance cells don't necessarily represent an allocated place…
16:55:09
jmercouris
jackdaniel: if you look at the book, I would say it is definitely wrong despite the linked spec, because it shows very clearly some slots in a table for a symbol
16:55:11
beach
If so, symbols also have SETF function cells, method-combination cells, type cells, class cells.
16:56:41
jmercouris
I think you were working on something involving speculative execution of branches or something?
16:56:53
_death
beach: yes.. but this conceptual association relation I'm talking about is not a symmetric.. see Tversky et al. :)
16:57:10
pjb
anything we explain is always pedagogical metaphore. Even when you try to explain things in the most objective way.
16:57:33
pjb
The only exact explanations AFAWK would be to give the wave function of the system we want to explain.
16:57:38
beach
jmercouris: One sort of can, but it is then running inside a host and not as a proper executable.
16:58:23
jmercouris
there are most definitely bits, if we define a bit to be a charge or a lack of charge
16:59:07
pjb
Nope. You could have seen some lumps of copper and you may have counted 64 of them somewhere, but that's meaningless.
16:59:33
beach
_death: I think those associations depend on the person doing the association. I have long thought about SYMBOL-FUNCTION as accessing the environment rather than the symbol.
17:00:10
jackdaniel
I'm certain I did, I've even blinked a few times (or skipped the blink); 6 times in total
17:00:14
pjb
Using an oscilloscope, you might have observed some change in the electric electromagnetic field but this is still no bit. And no symbol, no lisp object nothing like it.
17:00:17
_death
beach: certainly it's a valid way of thinking, and can lead to useful representations
17:01:53
pjb
That said, CL doesn't specify those environements as first class objects (the other kind of environment are first class objects, even if there's no public constructor and they cannot be introspected in CL).
17:04:25
pjb
(defun symbol-function (x) (gethash x (function-table *environment*))) is another valid implementation.
17:04:41
beach
jmercouris: It can be the name of a function, a class, a method combination, a type, etc.
17:04:55
pjb
CL doesn't specify the implemention of CL operation, only their interface and semantics.
17:05:36
Bike
Are you asking what the difference is between the symbol "having" a cell, and the environment version?
17:05:46
pjb
AFAIR, there are only 2 algorithms specified in clhs: the reader algorithm, the backquote algorithm. (And we may infer one or two other algorithms more).
17:06:09
pjb
But even those are only indicative: an implementation can use another algorithm behaving the same and those.
17:07:33
pjb
The thing is that you can both forget it or take it at face value, whatever helps you understand what you want to understand. (defstruct symbol name value function package plist) is a perfectly good explaination of symbols too.
17:07:50
beach
jmercouris: _death thinks that function cells and value cells are strongly associated with symbols, but not (say) classes.
17:07:56
jmercouris
pjb: the struct is actually how I usually imagine them in head, interestingly enough
17:08:00
Bike
i think this is something where you could talk about it for hours, or just write a simple interpreter and have it be obvious
17:08:48
jmercouris
beach: It makes sense though, why would a function cell be strongly associated with a class?
17:08:48
beach
jmercouris: I see symbol-function as similar to find-class, i.e. as operations on the environment.
17:09:02
pjb
(defstruct (symbol (:predicate symbolp) (:constructor make-symbol (name))) name (value *unbound*) (function *unbound*) package plist)
17:09:27
beach
jmercouris: Functions have names, so do classes. There is no particular reason to treat them differnetly.
17:10:00
_death
you can think of a symbol as an abstract data type, with certain behavior and various accessors, and any representation that fits that behavior will do
17:10:15
pjb
For example, one strong reason why we would want to have value and function outside of a symbol object, are threads (which are not specified in clhs). And having separate environments in the same lisp image is another reason.
17:12:35
beach
jmercouris: FDEFINITION also accepts names that didn't use to exist, namely (SETF CAR) and such.
17:15:14
pjb
(defun fdefinition (x) (etypecase x (symbol (symbol-function x)) (list (assert (eql 'setf (first x))) (get-the-setf-of (second x)))))
17:17:12
beach
jmercouris: Here is how I see it. In the old days, functions could only be named by symbols, so it was "natural" to store the function in a slot of the symbol, and to have a function called symbol-function. Then they introduced names such as (SETF FOO). Instead of adding a function symbol-setf-function, they created a new function FDEFINITION. It no longer mentions SYMBOL, so it is more "natural" to think of it as accessing the
17:18:30
pjb
Yes. Notice also that in the old time there were several kinds of functions fexpr, subr, etc. Nowadays, two kinds of functions can be bound to symbols: (symbol-function 'x) and (macro-function 'x).
17:19:26
beach
jmercouris: Given the name (SETF FOO), there was a need to find the corresponding function.
17:20:59
jackdaniel
that's why in cltl2 you could compare function names with eql and in ansi cl you can't (in the compiler)
17:21:03
pjb
But note that defun still use foo to name the block, not (setf foo), since block names must be symbols!
17:21:48
pjb
(defun (setf foo) (x object) (if (integerp object) (return-from foo x)) (error "expected an integer, not ~S" x))
17:21:49
beach
jmercouris: Because it is what (SETF (FOO 'BAM) 42) expands to if no setf expander has been defined.
17:23:11
jackdaniel
moreover, if you are not interested in being conforming: (defun (setf bar) (a b c object) …) (setf (bar 'xxx) (values 1 2 3))
17:23:28
beach
jmercouris: So now do you see why I don't think symbol-function or fdefinition are operations on symbols, but on the environment?
17:24:20
beach
jmercouris: And in fact, SYMBOL-VALUE probably doesn't access the "value cell" anyway, at least not in a multi-threaded Common Lisp implementation.
17:26:33
jmercouris
I'm going to rest as well, my mind is tired from thinking, thanks for the explanations everyone
17:39:11
_death
I think a good followup question you should have, with beach's model in mind, is why symbol-function and friends don't take an environment parameter
17:50:11
_death
also, weaker association between names and objects (first-classization) is something that appeals to many scheme-minded people
18:04:21
pjb
_death: that's because they're the standard API. (defun symbol-function (sym) (sicl:symbol-function sym sicl:*environment*))
18:06:02
_death
pjb: the begs the question.. I asked about the standard functions.. I agree that it's due to historical reasons
20:43:35
phoe
minion: memo for pfdietz: There's a comment I've made at https://github.com/phoe/package-local-nicknames-tests/pull/2 - did you have any insight about it so far?
21:14:30
phoe
Will the compiler then inline the code for these functions only in LOCALLY's lexical scope?
21:14:45
phoe
Like, if I declare A, B, C locally inline, and A calls B, and B calls C, will everything get inlined?
21:15:41
phoe
To define a function f that is not inline by default but for which (declare (inline f)) will make f be locally inlined, the proper definition sequence is:
21:24:54
phoe
If a function is locally inlineable, am I also able to compile it with different optimization settings?
21:25:23
phoe
Like, will I be able to compile it locally inline with speed 3 if the original function is compiled with speed 1?
22:41:24
pjb
phoe: you're doing something wrong: asking an implementation dependent question in #lisp instead of #sbcl or something.