freenode/lisp - IRC Chatlog
Search
3:20:10
sjl
When using &key (foo some-form foo-supplied?) in a destructuring-bind, shouldn't foo-supplied be bound to true if :foo is given in the call and false otherwise?
3:20:21
sjl
like, what am I missing here? https://paste.stevelosh.com/7c301026ece2efc869e5ce253f5ff56f98bbf307
3:23:28
Bike
it uses sb-int:binding* which can bind multiple values, and uses multiple values for the variables
3:23:33
sjl
yeah, it works properly in vanilla lambda lists -- only seems to be an issue in destructuring-bind
8:18:21
amazoniantoad
Hey guys. I'm trying to take two columns and generate a matrix from their multiplication. Could anyone show me how to do this? Currently I'm trying to do (elt (elt matrix i) j) and using setf to set the value. But instead of getting unique values for every cell I wind up getting the exact same row in the matrix
8:19:04
no-defun-allowed
Why are you using an array of arrays? Common Lisp has n-dimensional arrays.
8:19:34
no-defun-allowed
And are you talking about matrix multiplication, element-wise multiplication, or...?
8:21:32
no-defun-allowed
How do you get a 2D array from two 1D arrays? Something like O_i,j = M_i × N_j?
8:24:08
no-defun-allowed
Well, to make a 2 dimensional array, you can use (make-array (list columns rows)), and then (setf (aref <array> column row) value) to set an element of that array.
8:27:26
no-defun-allowed
(Using Petalisp, you could write (defun cross-multiply (a b) (petalisp:α #'* (petalisp:reshape a (petalisp:τ (i) (i 0))) (petalisp:reshape b (petalisp:τ (j) (0 j))))). I don't think Common Lisp is very nice for doing n-dimensional array work without some helper functions.)
8:29:14
phoe
I don't think amazoniantoad is a possible client for petalisp if he's still working on getting the basics of 2D arrays done - maybe in a few months, but not yet
8:29:45
no-defun-allowed
Writing a step between a JIT-compiling parallel array manipulation DSL and using big loops of (setf aref) is left to the reader.
8:46:08
no-defun-allowed
amazoniantoad: "element-wise" would probably refer to O_i = M_i + N_i, if I'm not mistaken.
8:56:37
pjb
Well, you can also use (map 'vector (lambda (x) (map 'vector (lambda (y) (* x y)) v2)) v1) which should be more efficient allocating temp storage, but still O(m*n) temp space.
10:13:30
flip214
Can a compiler macro (or normal macro) get the form(s) it's embedded in? SBCL only would work for that use case.
10:15:48
phoe
flip214: I don't think so. The only thing available is the environment, and that doesn't contain everything.
10:18:47
adlai
flip214: "The value of - is the form that is currently being evaluated by the Lisp read-eval-print loop." (obviously, doesn't work in files)
10:24:26
flip214
I've got a function that asks the user a question - and I'd like to determine whether the outer form wants a string, boolean, or number result
10:24:47
pjb
flip214: it cannot, and this is for the best. This is the best feature of lisp macros, not to be able to know anything about the outer form. This is what makes them secure!
10:25:41
pjb
flip214: however, there is macrolet (and symbol-macrolet), which can be used in the EXPANSION of an outer macro. (and also flet and labels).
10:26:32
flip214
pjb: yeah, and compiler-let, and similar stuff. I'm just wondering whether there's an easier way - #'<= in the outer form requires a number, string= a string, etc.
10:26:44
pjb
flip214: this let you design an outer macro, in which you can have access to a macro. The outer macro can arrange to give the information needed by the inner macro, even if comes from forms outside of the inner macro (but inside the outer macro, of course).
10:27:48
pjb
flip214: that said you are not allowed to shadow the fbinding of symbols in the CL package, or defining compiler-macros on them. So you have two ther reason why you won't be able to do that for <= or string=.
10:30:02
pjb
flip214: now, I don't think there's any guarantee about the environments for macro-expansion and compiler-macro expansion. I don't think you could conformingly pass information from a macro to a compiler-macro. This would have to be checked in the CLHS.
10:30:41
pjb
flip214: but once you have a wrapper macro, you don't really need compiler-macro, and this would allow you to do stuff on forms using symbols in the CL package as operators.
10:32:20
phoe
flip214: the outer form should pass the expected input type to the function, that's the cleanest way I can think of
10:34:59
flip214
phoe: Yeah, that's what I thought, too... I'd just like to avoid having my own code-walker, there are already too many of them ;/
10:35:41
flip214
I hoped that I there's an easy way to see what the outer function is - and then the expected type is easy...
10:36:35
phoe
flip214: if you want a true, absolute hack, use DISSECT at runtime to analyze the stack, figure out which function you were called from, and adjust the typecheck accordingly
10:38:56
flip214
LdBeth: most functions have input/output types already declared, and in the worst case I have to annotate the symbol
10:39:20
phoe
flip214: how about the symbol-macro trick then? you set a symbol-macro in the environment with the expected type that you can then macroexpand in the inner macro
11:10:01
flip214
LdBeth: the query function will only occur within AND, OR, <=, STRING=, and similar stuff. It's not general-purpose.
11:52:02
Bike
doing something different based on the return type sounds like a job for static typing. which is to say, might be in the wrong language here
11:55:08
flip214
Bike: why? a GF chooses a method based on the input type as well, so I'd see that as some kind of symmetry
11:56:51
Bike
if it actually chose a method based on the type, you could indeed have it do different things based on the output type. but that information does not necessarily exist in lisp.
12:14:04
Bike
despite the efforts of the best alchemists i can hire, i haven't yet restored my pineal gland to its ancestral power and so cannot read minds
12:14:28
Bike
anyway, things like apply and eval can mess up the concept pretty hard. even just calling something like that at the repl could be a type error for ambiguity
12:15:33
Bike
if you're only using this in specific contexts, you could have those contexts pass along an additional parameter expressing what kind of result is expected, sort of like COERCE