freenode/lisp - IRC Chatlog
Search
1:00:43
no-defun-allowed
Indeed. Though I assume you would want to make sure the returned form tests X, as the macro currently tests if the symbol PI is greater than 0.
1:01:50
Alfr
And as for why it doesn't work, macro expansion doesn't evaluate its arguments. Thus you're passing the symbol PI, and then X is bound to it, thus you're trying to evaluate (> 'PI 0).
1:03:17
bmansurov
Thanks both. Assuming I want to make that macro work, how do I pass the constant PI to the macro, rather than the symbol?
1:03:33
no-defun-allowed
If you really wanted to, you may write (defmacro positivep (x) `(if (,x 0) 'yes 'no))
1:05:37
bmansurov
I see. I guess I should share another example where the problem I'm trying to solve is more pronounced. Here it is:
1:06:31
White_Flame
however, in most cases, what you really want is to construct code that the compiler will collapse for you, instead of trying to fiddle stuff at this level
1:08:16
no-defun-allowed
You will have to decide if (> from to) at runtime, perhaps by replicating and generating (if (> from to) (loop ... to ...) (loop ... downto ...)). But this would again be better as a function.
1:08:25
White_Flame
this is a runtime decision you have to make, based on the actual runtime value being passed into a call; this isn't something you can statically resolve
1:09:03
bmansurov
OK, thanks. So there's no way to solve the above problem with macros other than creating two loops?
1:09:51
White_Flame
if you make 2 loops, you'll have a (if (> from to) (loop ...) (loop ..)), and if FROM & TO are numeric literals, the CL compiler should constant collapse one of them away
1:10:49
bmansurov
I went this rabbit hole because I didn't want to write a function with two loops. I appreciate everyone's responses.
1:11:46
White_Flame
even if you special-cased in a test for pi, what would you think ot generate for (seq x y) ?
1:19:34
bmansurov
My biggest gripe with Common Lisp is that at some point I got this macro stuff, but because I didn't practice writing CL, I forgot it. Learning Common Lisp is not like learning to ride a bicycle, unfortunately. I have to relearn this stuff. ;(
1:21:42
bmansurov
I don't know. For me, unlike JavaScript, for example, Common Lisp was hard to learn (even though I already knew how to program). It's even harder to retain that knowledge.
1:26:31
White_Flame
and of course the reason there's upto vs downto is that the exit comparison needs to be <= or >= depending on the direction
1:27:15
bmansurov
Thanks, I appreciate your help. I was more interested in getting ~to~ and ~downto~ working. As others have suggested, and as you have showed, there are many ways to skin this cat. I was after that specific way.
9:45:16
theothornhill
Hello! How do you decide between separate defmethods, or use the (:method) syntax on generic functions? Are there any tradeoffs with one or the other?
9:46:51
no-defun-allowed
Usually I put a class definition and any methods in the same file, so I would rarely be able to use :method syntax if I wanted.
9:47:07
beach
The latter requires the method definition to be in the same file as the DEFGENERIC form, so that's already a limitation. If you modularity requires them to be in a separate file you have no choice.
9:47:28
no-defun-allowed
But I use :method for "default" methods which the programmer should know about immediately sometimes, and whenever I use DEFGENERIC as a lazy person's pattern matcher.
9:48:03
beach
Or, you can use :METHOD when you have only a few methods that specialize to built-in classes.
9:49:43
beach
Methods defined with :METHOD are removed when the DEFGENERIC form is re-evaluated. Not so with separate methods defined using DEFMETHOD.
9:51:05
theothornhill
You mean the "old" version is removed if you change a :METHOD method and re-evaluate?
9:51:17
beach
But, yeah, I agree with no-defun-allowed. Often, the best place for a method specializing to some class C is in the same file as the DEFCLASS form for C, whereas DEFGENERIC forms are usually in a separate file.
9:52:26
beach
Or if you change some other aspect of the generic function, like the method combination.
9:58:22
vydd
Hey! I'm trying to do some CL programming after a relatively long time, and for my project I'd like to use https://github.com/plkrueger/CocoaInterface. However, it doesn't seem to play nice with asdf (or at least that's how it looks to me). There are docs on how to setup the environment using the ccl-ide-init.lisp file, in which *module-search-path* is updated to contain CocoaInterface, but when I quickload my project from sly, it
10:37:25
vydd
jmercouris: googling around, your named popped up in a discussion related to migrating CocoaInterface to use a system. https://github.com/nEXT-Browser/CocoaInterface doesn't seem to be available anymore. Did you ever manage to make it work, or did you hit a road block?
11:12:42
rumbler31
once long ago I played with something like that on windows, but the experience wasn't great, mainly because the cocoa interface on windows was likely incomplete
11:52:10
jmercouris
vydd: you’ll have to look at this repository : https://github.com/atlas-engineer/nyxt
11:53:26
jmercouris
I actually more or less use the objective c bridge independently of the cocoa interface after some point in time