freenode/#lisp - IRC Chatlog
Search
1:46:58
no-defun-allowed
You can use a special variable: (defvar *a*) (defun abc () (setf *a* 10)) ... (let ((*a* 5)) ...)
1:48:40
no-defun-allowed
DEFVAR is required so that the function ABC knows it is going to modify a special variable, but you can also (declare (special *a*)) in every use of the special variable.
1:49:56
no-defun-allowed
Another option is to use a box (a small structure with one element, or a 0-dimensional array), but then you have to unbox the value to use it and have to setf the value of the box to modify it.
1:50:38
no-defun-allowed
eg (defun abc (b) (setf (box-value b) 10)) (let ((a (box 5))) (abc a) (print (box-value a)))
1:50:51
no-defun-allowed
(The implementations of BOX, (SETF BOX-VALUE) and BOX-VALUE are left to the reader)
1:58:19
pjb
asdf_asdf_asdf: have a look at: http://informatimago.com/articles/usenet.html#C-like-pointers-in-Lisp
2:16:27
pjb
asdf_asdf_asdf: well, actually the problem is the function call, since it's pass by value.
2:17:15
no-defun-allowed
Another solution would be to create a closure and have the function call that to set the value: (defun abc (c) (funcall c 10)) (let ((a 5)) (abc (lambda (n) (setf a n))) (print a))
2:17:19
pjb
asdf_asdf_asdf: you could kludge it with defining defun defmethod let let* progv etc so that all the variables would be symbol-macrolets to closures.
2:27:01
asdf_asdf_asdf
no-defun-allowed, OK. But I want, that in scope (defun abc (c) value was changed, not in scope (let ((a 5)).
2:28:11
no-defun-allowed
Modifying the binding for C that ABC gets won't affect the binding for whatever is in the LET.
2:29:23
no-defun-allowed
You need to pass the value through some kind of "box" as you would in C, or use a special variable to let ABC modify the binding established by LET.
2:30:55
no-defun-allowed
As I said, (defun abc (b) (setf (box-value b) 10)) (let ((a (box 5))) (abc a) (print (box-value a)))
2:31:23
no-defun-allowed
The box can be a CONS (and the value its CAR), a structure with one value which is the box's value, or a 0-dimensional array whose only value is the box's value.
2:31:32
pjb
asdf_asdf_asdf: you are being dumb. This is lexical, therefore the variables are know to YOU when you write the fucking code! Just use different variable names!
2:32:38
pjb
and since we have pass by value, don't try to mutate the variable in functions, instead get the result!
2:33:12
pjb
(defun abc (a) (let ((x 5)) (if (zerop a) (setf a (abc 1)) (setf a 100)) (values a x))) (abc 0) #| --> 100 ; 5 |#
2:44:04
asdf_asdf_asdf
OK, thanks. Maybe I select option 1. How change local var into global var using declare? I (declare (special x)), not working.
5:50:22
beach
harovali: I don't know the answer, but when you use SLIME, it is probably better to use the SLIME inspector.
6:01:57
no-defun-allowed
harovali: If all else fails in Emacs, usually C-g will get you somewhere that isn't where you are.
6:09:07
emaczen`
Here is the link to the bounty: https://www.bountysource.com/issues/75202399-wanted-by-value-structures-in-sb-alien $365! Surely someone here has a decent status update?
6:17:52
Nilby
It's actually not that hard for x96_64 because structs are passed fairly simply, but there are a bunch of edge cases, and to do it for all architectures is much harder.
6:19:15
Nilby
CCL can pass structs, but CFFI doesn't know how to use it, so I started by developing a patch for that too.
6:20:15
Nilby
The only way I got libffi working on windows was to compile it under cygwin and the use it under non-cygwin.
6:21:55
emaczen`
I can use libffi for other functions, but when it involves a struct, I either defined the C struct for libffi incorrectly or used the C struct incorrectly (probably the definition for libffi since I can use libffi in other cases just fine)
6:23:15
emaczen`
beach: It really is only a little bit of C I need, than a few wrappers and then +95% lisp!
6:24:30
Nilby
I just realized maybe I don't really use anything that passes structs on linux. I think opengl interfaces use it though.
6:26:07
Nilby
Actually I don't even have cffi-libffi loaded on linux, so I must have only been forced to use it on window where you have to for kernel calls.
6:27:09
emaczen`
Nilby: I'm using GNUStep, and just about 10% of the methods use really only 4 structs NSPoint, NSRange NSSize and NSRect
6:27:29
emaczen`
there are like 2 or 3 other structs that I am aware of, but they aren't really even used
6:29:09
Nilby
If you're on x86_64, you can try just reading it off the stack yourself. Small structs like NSPoint are usually just sitting on the stack.
6:31:31
Nilby
There's some way I forgot, but you can basically just do assembly instructions in lisp. I think in CCL it was already in a lisp variable.
6:32:26
Nilby
I'm probably not the right person to ask, since I hardly ever do such things, and only worked on it for a week during a fit of maddness.
6:34:38
Nilby
But I found looking at CCL code was very instructive, and it works quite well on MacOS with the objective-C stuff.
6:34:50
emaczen`
Nilby: Well, you are giving me good alternatives -- finding it on the stack makes sense to me. It is very much a lower-level solution that I am inexperienced with but I am aware of how some of these things work and it makes sense to me
6:48:59
Nilby
sbcl mostly does it with what it calls VOPs, You can see examples in say src/compiler/x86-64/arith.lisp
6:52:14
Nilby
It seems like in every Lisp written in Lisp you can write assembly in lisp syntax at some level. ccl and sbcl do so, and even in the lisp machines you can drop down into the microcode.
6:54:58
emaczen`
Nilby: So from what I am looking at these VOPs define the base assembly instructions like move pop push etc, and then you can then use them in typical lisp prefix syntax?
6:58:21
Nilby
But sbcl and lisp interfaces do seem to stay compatible at least 10x longer than most software.
6:59:48
emaczen`
Yeah, it doesn't seem like something that would change a whole lot in my opinion but I don't really know what these SBCL devs are up to ha
7:01:30
Nilby
I would love to do that patch, but unfortunatly I get filled with disgust and anger when I look at aseembly code too much.
7:07:14
emaczen`
Nilby: Make a bunch of abstractions first? Or it looks like if you just do a little bit at a time you would finish before anyone else does...
7:11:46
beach
The "assembler" I am using for SICL doesn't have a surface syntax, so it would be impractical for humans to use it.
7:13:56
Nilby
beach: Nice. Can't be forced to program in it if there's no syntax, right? *finger pointing at head meme*
7:18:05
beach
Exactly. But that's not the main objective. The main objective is to provide a good interface for the code generator of the compiler.
7:18:32
beach
It seems silly to generate surface syntax, only to have to parse it immediately after.
7:25:01
beach
Also, if the protocol at this level is well defined, it would be straightforward to provide one or more versions of the surface syntax, should someone feel like programming such a thing.
9:11:06
beach
And it does not have any facility for defining memory contents other than instructions, because that is not useful for its intended use.
9:16:11
beach
It is not meant for separate compilation followed by linking. Just as a backend for Common Lisp compilers.
10:01:12
Duuqnd
It tells me that it can't find GCC, but when I manually tell it where GCC is, it breaks apart because it can't find "libffi.h".
10:05:50
Duuqnd
Well, the problem here is that I don't know where to put it where CFFI will find it.
10:06:27
Duuqnd
It doesn't find GCC to begin with, so I don't know what more problems will come from that.
10:09:18
galdor
I tried to clean it up once, but it's virtually impossible to modify without breaking obscure platforms
10:10:02
Duuqnd
I tried to change the Windows PATH environment variable, but it still won't find it.
10:10:45
Nilby
If you're using sbcl I think you can just get a copy of the libffi dll and put it in the sbcl directory.
10:13:29
Nilby
I usually have to run sbcl under cygwin to get it to grovel, and then you can run it not under cygwin. It's very annoying.
10:19:18
Nilby
That is usually better, but not always possible, since the many things like Windows kernel has struct passing APIs.
10:20:31
Duuqnd
It looks like the library doesn't actually use libffi, it just adds it as a dependency and never touches it again.
10:30:48
Duuqnd
Yeah, I noticed that while trying to load it. Oops. Well, I'm gonna try to compile libffi with MinGW and see if that works.
10:31:29
Shinmera
https://www.bountysource.com/issues/75202399-wanted-by-value-structures-in-sb-alien
10:33:01
Nilby
It seems like you usually have to tell it where to find the C compiler, like: export CC=c:/cygwin64/bin/x86_64-w64-mingw32-gcc.exe or something.
13:17:03
samlamamma
I'm doing some work on WebAssembly. It's very frustrating to read non-lisper's WASM, they spread their right parens around like discarded toe nails