freenode/#lisp - IRC Chatlog
Search
9:29:12
ogamita
(block found (nsubst-if nil (lambda (item) (if (eql item 42) (return-from found 42)) nil) '((1 . 2) (3 . 42) 4))) #| --> 42 |#
9:34:54
ogamita
loke: then it's easier to write it yourself, but you may have a look at: http://groups.google.com/group/comp.lang.lisp/msg/0c66e597e08be90d
9:38:28
ogamita
You have more considerations: depth, width of the tree (so can you use a recursive function or should you derecursive it), and you want to collect the finds.
10:02:48
norserob
Hi, I'm trying to write a JSN string to a UNIX domain socket, to control the mpv player. It works fine from the command line, but not from ccl. Here is a small example to pause the mpv player: https://gist.github.com/rfolland/6458fcce83c73c4645cf8793771e1d75
10:08:53
ogamita
nope. No flush, no send. Well, since you close, it should flush automatically, but since the close comes just after receiving the command, it's possible the problem is at the receiving end.
10:10:20
norserob
Tried a forec-output now, did not help. It is not a TCP socket, just a UNIX file socket
10:12:07
norserob
I appreciate the help, I've spent some time on this today. Now I can move on. Thanks again.
13:08:06
_death
hmm, last night.. surprised that the machine actually took my rubbish and produced a right result.. but the lisp trick (compare ENCODE and ENCODING) may be of note, used it many times for stuff like this.. https://gist.github.com/death/e330b4a48c87104de341ba3a11ff5836
13:18:24
neirac
I'm kind of lost creating a package. if my package has dependencies that are met using quicklisp how do I specify them using defpackage ?
13:29:06
Xach
quicklisp also has another concept in between project and system -- "release" -- which is a snapshot of a project at some point in time taken in some way
13:29:20
Xach
anyway, for relationship management, it is normal to define a system via a system file
13:40:23
neirac
I'm trying to implement a rest service is there any recommended packages to use ? I was looking at caveman2 at this point
13:41:47
Xach
I like to use hunchentoot, which is lower-level so that might not be the best option available these days.
14:11:54
neirac
I'm reading this https://leanpub.com/fullstacklisp/read#leanpub-auto-the-web-stack it's good for beginners like me.
14:15:48
jmercouris
can someone explain why these two structs are not considered equal: https://pastebin.com/LAsELupe ?
14:18:25
pfdietz
The problem is there is no such thing as a generally applicable equality function. It's inherently context specific. Baker had a paper on this, if I recall correctly.
14:18:48
pfdietz
It ties closely to why there's no general purpose hash function, and no general purpose copy function.
14:19:05
jmercouris
beach: here's the interesting thing, shouldn't it still be passing with eq? or is the issue the list of strings?
14:19:32
jmercouris
the list of strings is the issue I guess, if modifiers was purely a string, of all of the string elements concatenated, it would work, no?
14:20:04
Xach
jmercouris: EQ is only for the exact same identical object. an existing object will never be EQ to something that comes from MAKE-whatever (unless MAKE-whatever isn't really making)
14:21:37
pfdietz
My rule of thumb is to always use EQL instead of EQ, and let the compiler optimization to EQ if it can determine that's safe.
14:21:43
jmercouris
well, I see no solution then to using a hash-table with structs as keys, without using equalp, that's the only logical path
14:22:09
jmercouris
otherwise, what's the point of a hash-table if I have to maintain a reference to every struct?
14:23:34
jmercouris
my original problem was distinguishing between: https://pastebin.com/qf408e0h as keys for a hash table
14:23:50
jmercouris
however, I see now that I will have to use something other than a lowercase/uppercase to distinguish
14:24:42
jmercouris
Xach: that's the ultimate goal yes, but I was using lower case "s" as a modifier for shift and upper case "S" as a modifier for super
14:25:22
jmercouris
however, if equalp cannot distinguish between the two I gave above, and equal will simply not work for my hash table, then I must change from using upper and lowercase "s" to some other letter in the alphabet entirely
14:25:25
Xach
jmercouris: i think one common trick is to have an integer where some bits represent modifiers and the rest of the bits represent the code. that is a good hash key.
14:26:13
jmercouris
e.g. the printable representation of a key-chord struct makes it obvious what keys were being pressed at that time without reading documentation
14:27:00
jmercouris
I will then need to change how the actual keymaps are made, but that can be done
14:28:48
Xach
jmercouris: keep your struct, but have a function to produce a hash key from it. use the struct everywhere, but don't use it directly for looking things up in the table.
14:31:04
jmercouris
also what do you mean by a "Bad" key? is there a reason you capitalized "Bad"? is there some proper noun I should know about?
14:34:48
ogamita
jmercouris: "To continue, press any key." Now look at your keyboard, where is the Any key?
14:35:42
ogamita
https://www.google.com/url?sa=i&rct=j&q=&esrc=s&source=images&cd=&ved=2ahUKEwjss-a8xZ_fAhWtyYUKHfJXA0wQjxx6BAgBEAI&url=http%3A%2F%2Funcyclopedia.wikia.com%2Fwiki%2FAny_Key&psig=AOvVaw2Yez1b6kcTPLqEyQ7C2LZN&ust=1544884524204735
14:38:15
ogamita
It's basic logic: when you must press the Any key, if you press the key next to it, it will be the Bad key.
14:48:44
hectorhonn
i just realized, dynamic variables are just like c functions that take arguments by copy. right?
14:50:25
jdz
hectorhonn: There is nothing in C that is like dynamic variables. Except maybe passing a pointer to a stack-allocated location down the call chain.
14:50:31
jmercouris
so I will either have to transform them as you've suggested, or just change to SH
14:50:50
jmercouris
because otherwise I would find myself writing serialize and deserialize functions for mys truct
14:51:28
jmercouris
I have mentally decided yes, but I do not make all the decisions, I try to get input from everyone on the project
14:52:39
Xach
anyway, everything is a tradeoff, and one of the tradeoffs is performance, and sometimes that is valued too highly in favor of things that seem like the machine can do quickly, even if the other way is fast enough
14:52:41
jmercouris
everything is a trade, and I am well aware that I am incompetent in many respects, and competent in others, I do not trust myself fully to make all engineering decisions, however I do have an opinion, however unqualified it may be
14:53:05
Xach
it is just exciting sometimes to think about how fast an integer can be compared to another integer! so fast!
14:53:13
jackdaniel
in theory when you have nice and clean interface whose 3 of 8 values are what you look for you should use it
14:53:31
jackdaniel
in practice it is usually 8x slower as a general api and if it is a bottleneck you need to opencode the same computation
14:54:06
Xach
jmercouris: would someone with a key chord struct make changes to it? modify or mutate its parts?
14:54:33
jmercouris
unless they were a sadist, it is meant to be basically a way to store a key-chord event
14:54:35
Xach
oh, then you can get fancy and use an eq hash table and make sure that the same arguments produce the same (eq) key chord
14:55:25
jmercouris
so far it is doing very few comparisons, and I see no noticable decrease in speed
14:55:43
jmercouris
at one point I had several million entries in the hash table and I could still not physically distinguish the delay
14:57:15
Xach
Sorry, I have to walk to work and maybe get a breakfast burrito from the side of a van along the way now
14:59:03
_death
jmercouris: do you know of the function INTERN? well, you could intern key chords.. the problem is that it can be a bit circular, as you may need a mapping there too
15:00:11
hectorhonn
jdz: ok, maybe not entirely alike for c function that affects globals. what i meant was when a c function exits, whatever change that was made to the copy arguments get discarded. in that sense it is like the dynamic variables. CL on the other hand always takes function arguments by reference, never copy, unless let is used..?
15:03:01
jackdaniel
jdz: if you think about this, in lisp you pass them by value as well, but all values which programmer may put their fingers on is a pointer
15:03:40
_death
jmercouris: the idea is to have a single object instead of multiple equivalent objects
15:03:59
jdz
Terminology can be confusing here. I'm using the C one, where the different modes are "pass by value" and "pass by reference".
15:04:05
ogamita
struct pt { int x,y; }; void f(struct pt* p){ p=malloc(sizeof(*p)); } main(){ struct pt q={1,2}; f(&q); printf("%d %d\n",q.x,q.y); return 0; }
15:04:48
ogamita
jdz: in lisp a lot of values are references, just like in C you have to use pointers, because a lot of values are not firs class objects.
15:04:49
jmercouris
_death: I get that, but I don't understand how you could say (make-key-chord ...) and get the same object back
15:05:08
ogamita
jdz: a structure is not a first class object in C:you cannot pass it as parameter ("by value") to a function.
15:05:27
pfdietz
Numbers and characters are weird in Common Lisp. An implementation is allowed to copy them (as in, change how they behave with respect to EQ) at any time. So it's only good to use them in a way that call-by-reference and call-by-value are indistinguishable.
15:05:35
jmercouris
_death: wouldn't you have to wrap it in some function or something that returns the key-chord as a symbol?
15:05:37
_death
jmercouris: so you have a hash table keyed by say an integer representation of the key-chord that maps to the structure objects, and whenever you want to return a key chord, you get it from that table.. you wouldn't say make-key-chord, but lookup-key-chord
15:06:32
_death
jmercouris: I am not talking about symbols.. I mentioned INTERN for the concept of having an atomic object
15:07:49
ogamita
jmercouris: or look at how emacs does it, and for compatibility choose the same encoding.
15:12:49
jdz
The only similarity might be that yes, dynamic bindings are unset when stack-unwinding.
15:14:56
jdz
Not sure how that interacts with values allocated on stack in the presence of setjmp/longjmp (especially if pointers to such values are stored somewhere).
15:16:04
jdz
CL dynamic variable bindings work as expected in the presence of non-local transfer of control.
15:18:31
ogamita
This is a recent addition to C compilers, even if it has been standardized at least in c89, IIRC.
15:19:03
ogamita
And it doesn't make a deep copy, so if the struct contains pointers, you are sharing data anyways.
15:25:31
beach
It is interesting that some people have difficulties understanding what I call "uniform reference semantics". I mean, it's a very simple model compared to what C or C++ do.
15:26:35
Bike
i know in my case i started out learning (an oversimplified version of) what C++ does and expected lisp to be similarly confusing
15:34:45
_death
to further confuse people, you can also claim that Lisp has pass-by-name with macros :)
15:35:36
ogamita
or even with functions: (defun f (x) (set x 42)) (defvar *x* 33) (progn (f '*x*) *x*) #| --> 42 |#
15:37:56
_death
dlowe: (defun swap (a b) (rotatef a b)) (let ((x 1) (y 2)) (swap x y) (list x y)) => (1 2)
15:37:56
dlowe
if you pass an object to a function, they get an object that is EQ to the object passed, and mutating that object mutates it in all contexts
15:40:06
ogamita
(defun swap (a b) (rotatef (symbol-value a) (symbol-value b))) (let ((x 1) (y 2)) (declare (special x y)) (swap 'x 'y) (list x y)) #| --> (2 1) |#
15:40:12
_death
dlowe: when you pass an object to a function, a new binding is created (the reference to the object is copied)
17:36:47
sjl
Is there some way to do something like (:module "problems" :components ((:files "*.lisp"))) in ASDF, rather than listing out every file by hand?
17:37:25
sjl
Usually I don't mind the listing, but for stuff like Project Euler, Rosalind, Avent of Code, adding every problem file to the .asd file by hand is tedious.
17:42:07
fortitude
#.(mapcar (lambda (f) (list :file (namestring f))) (uiop:directory-files #P"src/")) or similar
17:42:51
fortitude
looks like UIOP:DIRECTORY-FILES returns absolute paths, so that won't quite work as-is
17:43:04
sjl
Yeah, I considered that, but was worried I'd need to do some magic to make sure the current directory at .asd read time is the same one as it's gonna be loading the components from
17:43:29
fortitude
that could be a problem, but for something you don't plan to distribute you might not have to care
17:44:57
jdz
I wonder if there's a way to override/implement some EQL method (specialised to particular system) that would generate the components...
17:45:21
sjl
jdz: although, that takes a system as an argument, and I'd need to use it as I was READing the system... so the system can't really exist yet
17:45:36
fortitude
sjl: you could also write some code to create the file list and paste it into your system file, if the list isn't going to change much
17:46:08
jackdaniel
I'd define a new component type subclassing module, for instance harvesting-module and work from that
17:46:26
jdz
Or maybe you'd create a class AUTO-POPULATED-SYTSEM, and make your system inherit from that.
17:46:37
sjl
jackdaniel: that's probably the correct way to do it, though ASDF's use of CLOS frightens me
17:47:23
sjl
jackdaniel: I mean, it's just for silly code problem websites, so I'm not super concerned
17:47:51
fortitude
verisimilitude: sjl wanted to dynamically include a list of :file components in an asdf system
17:50:03
fortitude
or extending asdf, as jackdaniel suggests -- I made a build system for another language that way once; was a lot of work, but it's certainly possible
17:52:05
sjl
But yeah, I'd imagine making a :greedy-module component is probably the Right Way to do it
17:52:33
fortitude
sjl: that might also be useful for other people (but it's a lot harder than the other hacks, if you're just concerned about convenience in your own projects)
17:56:24
pfdietz
I had a problem once with uiop:run-program not working properly with a certain shell. Had to wrap the shell command being executed in parens.
18:36:42
sjl
jackdaniel: neat. So to package this up, I'd make a (very small) asdf-auto-module system, then have :defsystem-depends-on (:asdf-auto-module) and then (:components (:auto-module "problems")) would Just Work?
18:38:50
Xach
rpw has written about a living system with which he would register the files he's working on and provides some terse repl commands to reload things in progress
18:41:18
jackdaniel
Xach: I don't understand, how is this different from (say) binding (asdf:load-system 'living-modules) to a symbol-macro |R|?
18:44:27
jackdaniel
uhm, thanks for explanation. I don't see much value in that, but maybe I lack some context/examples or it doesn't match my workflow
18:45:47
Xach
jackdaniel: he uses vi and a separate repl so he has incentives to make the repl more supportive and intelligent. that's one of the ways.
18:46:42
Xach
i don't always enjoy the asdf-as-recipe model where you write a system definition and then use asdf to do a ton of sometimes-opaque work and at the end you get a working system, except when you don't and you have to go back to fiddling with recipes.