freenode/#lisp - IRC Chatlog
Search
20:51:23
aeth
member typep is faster than find in a sequence, at least for characters (where the sequence is a string) and unlike the latter it can be entirely resolved at compile time (find will iterate even if everything's constant)
21:54:51
dacoda
I was wondering if it was possible to create an array displaced to another array of a different type
21:55:15
dacoda
For example, if I have one array of '(unsigned-byte 8) and I wanted to displace another array of '(unsigned-byte 16), is this possible?
21:55:28
dacoda
Otherwise, how can I re-use the data of the first array while interpreting it as 16-bit integers?
21:56:46
MichaelRaskin
I wouldn't expect this to work well, given that many implementations «tag» the data to keep track of types
21:57:43
dacoda
Hahahaha, that would be an interesting way around it! Just have a C function that takes in a uint8_t buffer and casts it to a uint16_t buffer, eh?
21:58:09
dacoda
I'm using it for a little toy script, and if that's the solution, I might as well write it in C
21:58:29
MichaelRaskin
Well, FFI has functions for direct manipulation of foreign memory, no need for the C function.
21:59:50
MichaelRaskin
Note that you give up any and all Common Lisp safety when you do foreign memory manipulations by hand…
22:09:27
dacoda
(let ((original (make-array 2 :element-type '(unsigned-byte 8) :initial-contents '(255 0))))
22:11:01
dacoda
Thanks for pointing me in the right direction, I'm going to mess around with this nonsense and see how it goes
22:11:18
dacoda
Ahhh, I wonder if the result of the convert-from-foreign is a new array or the same...
22:17:00
aeth
ah, I see, with-pinned-objects should behave similarly (but it isn't used in static-vectors)
22:45:24
aeth
You should probably use static-vectors because it's portable, but... I'm not sure if its implementation method in SBCL is better than yours and what the various drawbacks are.
3:48:14
akkad
Error: Reader macro conflict while trying to merge the dispatch macro characters #\# #\U
6:18:02
beardio
I use Emacs as an editor, started teaching myself lisp, bought ANSI common lisp and Land of Lisp. Came here to learn, while I work thru the exercises.
8:14:39
makomo
i need some advice regarding interpreter design. i have a "component" (concept of the object language, the one i'm interpreting) which stores variables within it. a component has multiple "processes" which contain code to be executed
8:15:46
makomo
i would like to be able to use arbitrary lisp expressions as arguments for certain instructions within the code of a process
8:16:35
makomo
putting all of the safety issues aside for a moment, what's the best way to evaluate this expression (which can be an arbitrarily complex lisp expression), but within a context where the variables within the component are bound
8:17:40
makomo
so for example, say we have a component with the variable a = 1 and we're executing the instruction '(format t "~a" (sqrt a)) within a process of this component
8:18:05
makomo
i disect the instruction, get to the argument '(sqrt a) and somehow EVAL this but within such a context so that a is bound to 1
8:18:50
phoe
I think your best bet is to construct an anonymous function form (lambda () (let (...) ...))
8:28:59
nirved
makomo: you might look at Let Over Lambda, https://letoverlambda.com/index.cl/guest/chap2.html
8:33:21
makomo
i just thought there might be a "prettier" way, but then again i'm not sure why i feel so wrong about it
8:35:31
pjb
In general code changes less often than data, so a compiled function is usually more efficient.
8:36:09
pjb
If you consider translating to compiled functions, then it may be more efficient to avoid the hash-table for storing the component fields.
8:36:30
pjb
Also consider that if you have less then 5 fields (or 35 in clisp), a a-list is faster than a hash-table!
8:36:33
makomo
pjb: in this case i'm generating code from data though. upon every evaluation i generate the LET that binds the symbols to their current values
8:37:10
pjb
That's the point. with eval you have to generate a new let form. But if the body doesn't change, it's not efficient.
8:37:32
pjb
Well, we already discussed it, there's no clear-cut distinction between interpretation and compilation.
8:37:52
pjb
But in a way, yes, we could say that I'd nudge you toward a transpiler. It's usually easier than a pure interpreter.
8:38:30
makomo
maybe that goes just for the first few steps and after that it just becomes a pain because of "issues" like the above?
8:39:29
makomo
right now i have 2 classes, one describes the component's class, the other describes the instance of this class
8:40:35
pjb
I guess it's time for you to read The Art of the Meta Object Protocol. https://mitpress.mit.edu/books/art-metaobject-protocol