lainchan / λ

Lisp General: (MAKE-INSTANCE 'LISP-GENERAL :TITLE (PRINC-TO-STRING -) :ID 15857)

(princ tripcode) -| · 2019-11-07 23:30
This is the Lisp General, ask any and all Lisp questions here. Below is a link to the general's texts which contain many links to various books, documentation, websites, and other interesting information. >Check the texts first: http://verisimilitudes.net/lisp >To foster discussion: Which dialect do you prefer? Do you use Emacs or a different lisp-based editor? What was your first experience with lisp? What have you made in lisp? What is your favorite Lisp program? What do you like about Lisp? How do you think Lisp is (one of) the superior programming language(s)? How long have you been programming in Lisp? What are your favorite Lisp resources? Please share, preferably links! Is Lisp your main programming language or not? Regardless, what do you primarily use it for? What would you like to see in the Lisp general? What was your favorite aspect of the Lisp machines? Do you think we'll ever get something similar to the LispMs again? What is your preferred method of documenting your code? In the dialects that allow it, do you make many reader macros or not? Do you use more than one dialect? What are they and which do you prefer? What do you consider the criteria for what constitutes a Lisp to be? What is your favorite function in your chosen dialect(s)? Challenge: Implement something which is meant to interact with the outside world, in a way that's purely Lisp. An example is implementing a network protocol by only implementing the message processing, leaving the actual transfer for elsewhere.
Wirth · 2019-11-14 09:20
Spurred by seeing people compete with C in Haskell and APL, concerning the trivial wc program, I wrote this in a few minutes and turned it into an article: http://verisimilitudes.net/2019-11-12 I wrote a horribly naive implementation and yet the internal buffering had it perfectly competitive, with no real effort on my part. What Common Lisp have you written most recently?
hash table · 2019-11-15 04:57
Is Scheme a good introductory lisp?
Dr. X · 2019-11-15 06:56
>>15903 i'd say so. one hangup for a lot people getting into this kind of stuff is the syntax. scheme has weird syntax in that you use a lot of parenthesis, but otherwise it's pretty straightfoward. this is ideal because you can focus on learning the concepts of software. are you asking becuase you are planning on reading / taking sicp?
Tequila · 2019-11-15 19:46
>>15903 I switched over to ANSI CL from R5RS Scheme a little while ago. It was very jarring to go from a basic lisp like Scheme over to ANSI CL. It took a while to learn new syntax and reserved words. Because of that rough experience, I recommend going straight for whatever lisp you plan to use. So if you plan to use Scheme, learn Scheme. If you want to use ANSI CL, learn ANSI CL.
DEBUG-CONTENTS · 2019-11-15 21:19
>>15903 I'd say yet, but you will be missing out on some of the things that make CL or other Lisp-2's interesting. >>15905 he asked for a good lisp, I think he's ready to take the parentheses.
Lord Nikon · 2019-11-26 19:44
I've run into a weird behaviour I don't really understand. Working through old Advent-of-Code problems to have some first real stuff to implement, noob both to lisp and programming in general so my code might be a tad weird. (defun visited-houses (x) (let ( (visited 1) (temp-char nil) (currloc (list 0 0)) (beenloc (list (list 0 0)))) (dotimes (i (length x) visited) (setf temp-char (char x i)) (cond ((equal temp-char #\>) (incf (first currloc))) ((equal temp-char #\<) (decf (first currloc))) ((equal temp-char #\^) (incf (second currloc))) ((equal temp-char #\v) (decf (second currloc)))) (unless (member currloc beenloc :test #'equal) (incf visited) (setf beenloc (append beenloc (list currloc)))) ))) Problem is the variables set from within the cond and the unless behave differently. From the unless form it's as if every iteration is the first, leading the resulting visited to be 2 regardless of input (except empty string), and the set/list of visited locations never grow larger than 2 elements. Even though the variables incremented from the cond clauses work as intended and retain the accumulated results between iterations. So I'm confused to say the least, is there something I'm missing here?
Lunch · 2019-11-27 12:13
What would be the best Lua analogue from the Lisp family for video game scripting?
tadni · 2019-11-27 21:54
>>16021 Probably ECL? A small, but complete Common-Lisp Implementation; Extremely portable, and true to the name --"embeddable" in C, so aprox use-space as Lua. Alternatively, if you want to stay on the Luajit; Haven't messed with it at all personally ... but 'Urn' looks like a pretty nice compromise.
Frank Garza · 2019-11-28 11:40
>>16021 A number of games have been scripted in Scheme (for example the original Crash Bandicoot). Some people have written articles on the subject: https://www.silicondelight.com/embedding-tiny-scheme-in-a-game/
Crash Override · 2019-11-28 13:18
>>16034 On the Urn note, there's also Fennel for a Lua based Lisp. Ripping a comparison from a comment (not mine) elsewhere: "tl;dr Urn is a much bigger language that happens to compile to Lua as an implementation detail. Fennel is much closer to Lua and is dramatically simpler, only diverging from Lua semantics when the changes can be implemented purely at compile time."
Nameless · 2019-11-28 18:11
>>16016 Ignoring the problem, just a few style points: >(let ( never let a line end on open parentheses. >(setf temp-char (char x i)) just use a let in your dotimes, or consider using loop >(cond consider using case >(unless (member currloc beenloc :test #'equal) afaik, member uses equal by default
Neo · 2019-11-29 09:01
>>16049 >never let a line end on open parentheses Noted! >just use a let in your dotimes That was just me being lazy to be honest, the setf was less typing than another let form. Kinda shooting myself in the foot to practice with bad form though, not like my habits will change on their own when I'm making something real instead of exercises. >consider using case Oh! Figured there'd be a better way to write that, instead of repeating the same test. Been learning out of the Gentle Introduction book by Touretzky and case is never introduced in that. >afaik, member uses equal by default Seems not, only added that because with the default test this evaluates to NIL: (member '(0 1) '((0 0) (0 1) (1 1))) But with equal specified it works as intended for my function. Rewritten version using the suggestions (and hopefully keeping the formatting this time): (defun visited-houses (x) (let ((visited 1) (currloc (list 0 0)) (beenloc (list (list 0 0)))) (dotimes (i (length x) visited) (let ((temp-char (char x i))) (case temp-char (#\> (incf (first currloc))) (#\< (decf (first currloc))) (#\^ (incf (second currloc))) (#\v (decf (second currloc)))) (unless (member currloc beenloc :test #'equal) (incf visited) (setf beenloc (append beenloc (list currloc))))))))
x<->y · 2019-11-29 18:14
>>16052 Looks better, it just seems two of my prior comments conflicted, as you don't need the "(let ((temp-char ..." when you're using "case". >Been learning out of the Gentle Introduction book by Touretzky and case is never introduced in that. Consider browsing the Common Lisp HyperSpec (http://clhs.lisp.se/), the Simplified Reference (http://jtra.cz/stuff/lisp/sclr/index.html) or printing out Quick Reference (http://clqr.boundp.org/). >Seems not my bad, got confused with scheme. Algorithm-wise, I sat down to think about it and the first thing I noticed was that, if implemented correctly, the invariant (length beenloc) = visited should hold, and since you need "beenlock" to remember where you've been, you can safely drop visited. Also, you don't need to initialize your first step, since your algorithm would already do that for you. Just to show you how loop looks like, this could be an alternative implementation, although I'm certain there's a clever'er way to do it still: lisp (defun new-visited-houses (input) (loop with x = 0 with y = 0 for direction across input do (case direction (#\> (incf x)) (#\< (decf x)) (#\^ (incf y)) (#\v (decf y))) unless (member (cons x y) visited :test #'equal) collect (cons x y) into visited finally (return (length visited))))
dictionary · 2019-11-29 18:15
>>16061 Ugh, I hate lainchans code formatting. I've uploaded it here, should be easer to read: https://0x0.st/zI7v.cl
Knuth · 2019-11-30 10:56
>>16061 >seems two of my prior comments conflicted Oh yeah, didn't spot that. Need to remember to not just rewrite but rethink as well. >(length beenloc) = visited I did consider that when I first put it together, but opted for the counter approach instead for some reason, don't remember why though. >defun new-visited-houses I remember reading somewhere that some considered loop not-that-lispy, and I get what they mean now looking at it, feels like it's missing some parentheses on first gaze. Splitting the xy coordinates up and consing them together later does look much neater. There is an error in there though, the first iteration skips over the point of origin, so it will be off by -1 unless the iterations lead back over (0 0). Also rewrote my dotimes-version, using the cons angle... And now it works, for some reason. I'm not sure if I should be happy that it works or annoyed that I don't understand the reason why. Only real difference I can spot is that it deals with lists of dotted pairs instead of lists of lists now, maybe that messes with something. (defun visited-houses (input) (let ((x 0) (y 0) (beenloc (list (cons 0 0)))) (dotimes (i (length input) beenloc) (case (char input i) (#\> (incf x)) (#\< (decf x)) (#\^ (incf y)) (#\v (decf y))) (unless (member (cons x y) beenloc :test #'equal) (setf beenloc (append beenloc (list (cons x y)))))) (length beenloc)))
Judge Fang · 2019-11-30 21:12
>>16070 >There is an error in there though, the first iteration skips over the point of origin, so it will be off by -1 unless the iterations lead back over (0 0). Oops, you're right. >I remember reading somewhere that some considered loop not-that-lispy, and I get what they mean now looking at it, feels like it's missing some parentheses on first gaze. I don't thin "parentheses" make something lispy, you could write c with lisp syntax, but that wouldn't make it the same. The loop macro is interesting because it defines a new language within the existing language, to easily express many algorithms. Learning loop just makes a lot of things a lot easier. There's no reason the syntax should be a burden, and one thing that makes lisp interesting is that it doesn't have to be. But if you insist on parentheses, take a look at iterate (https://common-lisp.net/project/iterate/). >I'm not sure if I should be happy that it works or annoyed that I don't understand the reason why. Oh, that's simple. You kept adding the same list to the list of visited points, but since you used incf/decf you changed the value of all the points, meaning that in the end you only had a list of equal (and eq) elements. Also another tip I forgot to mention, check out push and pushnew. You can avoid using (unless (member ...) (setf ...)), and generally you can avoid (setf ... (append ... (list ...))) with push.
Tyrell Wellick · 2019-11-30 21:14
>>16070 And the third argument to the dotimes spec seems unnecesary, or could be replaced by "(length beenlock)".
Car of an atom · 2019-12-05 13:49
Jane Doe · 2019-12-05 14:04
>>16070 >>16076 I don't want to derail the discussion but the loop function is in fact very unlispy. Iterate does the same but maintains the Lisp syntax and thanks to that it's much easier to work with for macros and such stuff. I believe it also gives you the ability to access the loop deeper in your code instead of just at the top level of the loop which is very useful at times. Loop is a bit of an abomination when you look at iterate and see what we could have had instead. Hopefully the next standard will adopt it.
Lain Iwakura · 2019-12-05 23:01
>>16119 Lisp syntax is anything a lisp system accepts, loop is no less lisp than iterate. True, it's atypical. But if "being a lisp" is "having a lot of parentheses", I think that's a rather shallow definition. That's not to say that there are other reasons to prefer one over another. Loop's main strength is that it's standard, which is not non-negligable. Iterate has be benefit of hindsight, among other things. But to say that one is "more lispy" than the other is not an argument.
Erik Johansson · 2019-12-06 09:41
>>16126 >Lisp syntax is anything a lisp system accepts, loop is no less lisp than iterate. Yes and no. While that's technically true, there's a way we do things in lisp usually and that's what we mean when we say it is or isn't lispy. If it doesn't fit the philosophy of the rest of the language then it feels off and is not lispy. >True, it's atypical. But if "being a lisp" is "having a lot of parentheses", I think that's a rather shallow I never said this. In fact, my post was giving you several reasons why this is. Loop's syntax does not work well in lisp because it breaks a lot of macros. Iterate fixes this by sticking to s-expressions which is what almost all macros are written for. It doesn't make sense to develop a new syntax for loop when s-expressions to the job even better and are the syntax of the rest of the language. Sure loop works and it's a very powerful tool but it not being lispy is most definitely a valid argument, it broke the Lisp syntax for no good reason (maybe there are historical reasons but that's beyond us) and we should fix it.
Turner · 2019-12-06 22:45
>>16130 >there's a way we do things in lisp usually and that's what we mean when we say it is or isn't lispy. If it doesn't fit the philosophy of the rest of the language then it feels off and is not lispy. Who's we? I don't think it makes much sense to discuss this, since due to the different backgrounds and histories of lisp programmers, there is no single predominant "we". And again, I'm not saying both are equally good, just that neither is more "lispy". I have to admit that I don't know what macros you are talking about, but either way that doesn't make it less lisp. I would probably even use iterate if it were to be adapted into the standard, but not because of the parentheses, but because of it's technical qualities.
Mitnick · 2019-12-09 03:14
>>16119 >loop function is unlispy loop is a function? This whole time I thought it was syntactic sugar for some kind of efficient and clever iterative function
Koichiro · 2019-12-09 18:10
>>15825 (previous lisp thread) >This is the train scheduling system I was thinking of, SISCOG: https://www.siscog.pt/en/ I was just going to comment that this is the sort of work that one should dream of doing. Innovative quality work that actually materially benefits society, in a space where every member of your relatively small team is considered vital, and input valuable. >As for writing machine code in Lisp, I have my own development tools, so I'm not inclined to work in that way. I delayed response to this because I didn't want to sound in any way rude, I know you've put quite a lot of thought into the design of your MMC. I'd imagine in the future you'd want a Lisp editor which operates in a similar way, with binary encoded source, questions/holes, and modes for one-to-one binding of various functions. Given this Lisp editor did exist I was wondering what your thoughts would be on having the ability to use your MMC to render to a Lisp representation for the sake of using macros on this Lisp representation, and calling Lisp functions (maybe). After writing these assembly macros could then call the macro-expander and jump back into the MMC as a sort of narrow and mode change to view and edit your expanded assembly, switching back and forth as desired. When you're done the editor could replace the Lisp representation of assembly with a foreign function call to the assembly in separate file. This might be a bit pie in the sky considering how much infrastructure would need to be established before you could do this but I'm curious on your thoughts none the less.
Dr. X · 2019-12-09 18:11
>>16167 It's actually a macro, I made a mistake.
recursion without exit · 2019-12-10 20:39
Did someone here use picolisp?
(princ tripcode) -| · 2019-12-11 09:01
>>16172 >I was just going to comment that this is the sort of work that one should dream of doing. I'd rather pursue a grant to work on my own work by myself, without worrying over funds. When someone discusses the idea of a dream job, my answer of money for nothing isn't received too well, generally. >I delayed response to this because I didn't want to sound in any way rude, I know you've put quite a lot of thought into the design of your MMC. Oh, I thought you'd delayed your response due to my taking so long to respond in the Ada thread. I saw that post the day it was made, yet I didn't respond for a ways. Don't worry about offending me. I take it since you're familiar with my work we've either had a discussion before or you've read it on my Gopher hole or website. >I'd imagine in the future you'd want a Lisp editor which operates in a similar way, with binary encoded source, questions/holes, and modes for one-to-one binding of various functions. I'm thinking further than that, but sure. I want structure editors and an easier time programming. I want specialized tooling that does as much for me as it can. >Given this Lisp editor did exist I was wondering what your thoughts would be on having the ability to use your MMC to render to a Lisp representation for the sake of using macros on this Lisp representation, and calling Lisp functions (maybe). I once considered making my MMC a more general tool that could be controlled in this way, although I've purposefully tried to forget about the horrible tangent. My opinion is that writing such programs are effectively writing compilers and the point of my MMC is to write machine code, not input for compilers such as this. It would potentially be bothersome, to write a little compiler that could truly account for things as a human would. I've recognized that the one-instruction-at-a-time interface could be considered a weakness; after all, macros can be useful, but this really just solidifies the ethos of this tool, which is programming where each individual unit of memory should be carefully thought about and accounted for. Where assembler language programmers write macros, I write subroutines and call instructions, which make my programs smaller. I'm certainly not describing the full breadth of my thinking here, but I believe this communicates the gist well enough. >After writing these assembly macros could then call the macro-expander and jump back into the MMC as a sort of narrow and mode change to view and edit your expanded assembly, switching back and forth as desired. Jumping back and forth in this manner could be workable, but at the same time it's not inconvenient to write several instructions in sequence. Further, I've been getting better (and worse after long enough) at using my interface; in the current targeting, I have several categories of instructions, and each category and some others have different default answer storage, meaning I can very easily press the keys and use the defaults without change to quickly write or change any instructions I may need to repeat, as an example. >When you're done the editor could replace the Lisp representation of assembly with a foreign function call to the assembly in separate file. I don't understand the purpose in this. I wouldn't want to use the machine code from Lisp. >This might be a bit pie in the sky considering how much infrastructure would need to be established before you could do this but I'm curious on your thoughts none the less. The following is a quote from Coders at Work: >Seibel: Alan Kay has said that both Lisp and Smalltalk have the problem that they're so good they eat their children. If you had known Lisp, then Smalltalk would have been the first eaten child. >Ingalls: Maybe so. I want to stress that there are many other reasons and that I enjoy Lisp, of course, but this is another reason I won't tie Lisp so closely to my more novel work, beyond being an implementation language. I won't allow my children to become those of Lisp, only for them to be eaten. Other reasons are that Lisp doesn't do everything I want, my fascination with numerical formats, and my yet future programming work I believe may very well be capable of exceeding Lisp, among other things. I've similarly not described the full breadth of my thought in this, but I believe you'll probably understand my meaning with it.
Shogun · 2019-12-11 11:10
>>16207 >money for nothing I know right? I have had a lot of dreams in my life. None of them were jobs.
Unspecified · 2019-12-13 00:17
>>16207 >I'd rather pursue a grant to work on my own work by myself, without worrying over funds. That's fair enough. >Oh, I thought you'd delayed your response due to my taking so long to respond in the Ada thread. I saw that post the day it was made, yet I didn't respond for a ways. Don't worry about offending me. I probably would have responded to both parts of your message at the same time had I not been afraid that my message here might have been offensive, wasted your time, or in some other unconscious way been not worth writing. I went ahead and sent it because you said that you were anticipating it. It seems to a significant degree I've misunderstood the ethos of your tool as you said. I thought you were striving to expand understanding through a thoughtfully designed assembly programming environment, and to write certain software which you wouldn't want to write in a higher level language. You seem to be striving for practical perfection following your own criteria however. With this in mind it seems reasonable that macros might be too course a tool, and a unnecessary tool at that given the ergonomics and efficiency of other the tools you've created for your self. Additionally it makes sense that macros and interoperability with high level languages is in contradiction with the ethos. I misunderstood your comments in the previous thread as expressing desirability of replacing tight loops in garbage collected languages with assembly similar to GOAL, except that you have your own tooling that does otherwise and these two cannot meet but you seem to have been more commenting on the viability independent of the desirability. >I want to stress that there are many other reasons and that I enjoy Lisp, of course, but this is another reason I won't tie Lisp so closely to my more novel work, beyond being an implementation language. I won't allow my children to become those of Lisp, only for them to be eaten. I suppose that makes sense if you are trying to create something truly distinct, I'm assuming these quotes have more to do with integration than infanticide, but it's inevitable that in this process the idea to be integrated would have to be modified, and perhaps sullied by the integration. >Other reasons are that Lisp doesn't do everything I want, my fascination with numerical formats, and my yet future programming work I believe may very well be capable of exceeding Lisp, among other things. I've similarly not described the full breadth of my thought in this, but I believe you'll probably understand my meaning with it. I look forward to seeing what you're capable of.
(princ tripcode) -| · 2019-12-16 08:55
The only Lisp work I've been doing lately involves an implementation of SHA1 I'm planning, which would fulfill the previous thread's challenge. I've already and recently written SHA1 in APL and Ada, dealing with bits and words respectively, and the Common Lisp will fill this set in by focusing on octets. It's good to write programs performing the same tasks in my main languages, as I learn from it. Common Lisp permits logical operations be performed on integers, whereas APL restricts them to bits, but APL makes it far easier to segue from one representation to another. Ada requires me to define my own types and other such things and it's important to make types private where this is reasonable, whereas the Common Lisp requires no such thinking in comparison, as I'll simply be storing intermediate SHA1 state as a BIGNUM; Ada also makes it very easy to think of a single good name and then overload it, whereas I must use CLOS to get something similar. >>16220 >It seems to a significant degree I've misunderstood the ethos of your tool as you said. I thought you were striving to expand understanding through a thoughtfully designed assembly programming environment, and to write certain software which you wouldn't want to write in a higher level language. You seem to be striving for practical perfection following your own criteria however. I've realized the tool could have pedagogical value, despite being designed solely for my use in hardcore machine code programming. As you probably know, I've written several articles using it in which I don't write any machine code, but instead load in and document machine code written by others, so it has value in disassembling and exploration, as well. As for what I write with it, in many ways I simply want to expand my knowledge and have the option of writing optimized machine code; this is a simplification, but I merely mean I don't offhand recall having any particular software in mind besides perhaps the base of a higher language and system routines which would need to be written at this level; I'm not trying hard to recall anything else currently, note. Ultimately, the tool exists because I thought of the idea and wanted to breathe life into it and it changed from my initial envisioning borne of boredom, but now it exists in some form and that pleases me a decent ways. >I misunderstood your comments in the previous thread as expressing desirability of replacing tight loops in garbage collected languages with assembly similar to GOAL, except that you have your own tooling that does otherwise and these two cannot meet but you seem to have been more commenting on the viability independent of the desirability. That seems like something I'd do, yes, without revisiting those posts to double check. >I suppose that makes sense if you are trying to create something truly distinct, I'm assuming these quotes have more to do with integration than infanticide, but it's inevitable that in this process the idea to be integrated would have to be modified, and perhaps sullied by the integration. Yes. >I look forward to seeing what you're capable of. It's so nice and flattering to read that.
Nobody important · 2019-12-23 02:44
>>16241 >Ultimately, the tool exists because I thought of the idea and wanted to breathe life into it and it changed from my initial envisioning borne of boredom, but now it exists in some form and that pleases me a decent ways. I'll just say that this reminds me of "Against Method" and say I enjoyed the conversation, thanks for your time.
queue · 2019-12-30 04:48
I'm learning scheme and decided to try to implement my own interpreter/compiler as a way to try out what I've learned. I'm a little confused about how I would go about implementing an AST in scheme or lisp. It's pretty straightforward in C since I could use pointers, but not so much in scheme. Any advice or examples you all can recommend?
Erik Johansson · 2019-12-30 11:27
>>16349 Just use lisp as your AST. Other than that, every non-atom (cons-cells, vectors, ...) are implicit pointers, but in the end, you'll be doing the same thing as a "(read)" would do.
Linda Lee · 2019-12-30 18:30
>Reading Guile documentation >Written exclusively using female pronouns to refer to devs and users Why would you do it this way
Unknown · 2019-12-30 19:50
>>16362 https://www.gnu.org/software/guile/manual/guile.html ctrl-f 7 instances of 'he', all referring to specific males. 4 instances of 'she', all referring to unknown persons. The point is obviously to Rian Johnson your expectations, but I am disappointed that this isn't more offensive.
Donna Hawthorne · 2019-12-30 22:25
>>16362 >>16363 I can only find three instances of she in the texinfo source, and it appears that they are at least from 2001: http://git.savannah.gnu.org/cgit/guile.git/commit/doc/ref?id=a0e07ba4ec As far as I see whoever wrote the documentation, just chose to word it that way in the first place, so I guess it's just personal preference.
Dox · 2019-12-31 01:03
>>16357 Let me rephrase: I am literally following a guide on how to build a compiler using C and trying to rewrite it in Scheme. I have absolutely no idea how to "use lisp as your AST".
Switch · 2019-12-31 15:58
Is there a good introduction to common lisp aimed at people who already know scheme?
Crash Override · 2020-01-01 09:44
>>16367 You don't need to use pointers in scheme. A typical way to make a linked list in c is to use a struct that stores a pointer to the element and a pointer to the next node of the list. In scheme you store the next node directly instead of storing a pointer to the next node. So to represent (1 2 3) you'd do (cons 1 (cons 2 (cons 3 '()))) with '() being the empty list. the first node (cons 1 ...) contains the rest of the list (cons 2 (cons 3 '())) directly instead of storing a pointer to the rest of the list. You store a pointer in c because structs require elements to be a specific size, so you can't store an arbitrary number of elements directly. The usual way to handle trees in scheme is to make trees lists that can contain lists. The internal lists represent subtress, so (+ 1 (- 3 2) 4) would be (list + 1 (list - 3 2) 4) where list is a function that takes n arguments and wraps them into a list (cons first-elem (cons second-elem ...)). So to evaluate the arithmetic expression you'd evaluate numbers by not doing anything to them, and you'd evaluate lists by evaluating all but the first of their elements and then calling the first elem using the rest of the elems as arguments. > (define (eval-nonempty-arith-expr t) (cond ((number? t) t) ((list? t) (apply (car t) (map eval-nonempty-arith-expr (cdr t)))))) > (eval-nonempty-arith-expr (list + 1 (list - 2 3) 4)) 4 In the example above, 2 and 3 get left alone. Then - gets called on 2 and 3 producing -1. Then 1 and 4 get left alone. Then + gets called on 1, -1, and 4 producing 4. If you encode trees this way then you can't store lists directly because they would be interpreted as subtrees. For implementation reasons, list? iterates through all of it's elements in a linear time operation, so it's common to use pair? instead which just checks for a cons instead of checking if the conses end in an empty list. > (define (eval-nonempty-arith-expr t) (cond ((number? t) t) ((pair? t) (apply (car t) (map eval-nonempty-arith-expr (cdr t)))))) > (eval-nonempty-arith-expr (list + 1 (list - 2 3) 4)) 4 The downside of this is that you can't represent a pair as well as a list. In this example the language uses apply to evaluate the expression, if you were writing a compiler you could return instructions that push the rest of the elems onto a stack instead. It's difficult to explain succinctly, if you don't understand something I might be able to clarify further.
(princ tripcode) -| · 2020-01-04 00:00
I wrote my SHA1 in Common Lisp a little while back: http://verisimilitudes.net/2019-12-25 I'm reasonably pleased with the design, using a single SHA1:HASH generic function with several methods, for convenience, and discouraging USE-PACKAGE. I've not yet reviewed and cleaned the code as much as I would care to, but feel free to tell me what you think, in any case. >>16385 I recently wrote an article regarding learning programming languages, 2020-01-02, and as I explain therein, if you already know Scheme, I see no reason to not start with Common Lisp, the Language: 2nd Edition, or perhaps a beginner's text if you find that unpalatable. I'm of the opinion the only barrier to learning Common Lisp so directly is perhaps unfamiliarity with Lisp in any way, but you don't fall into that category.
JARGON · 2020-01-11 19:34
Is web dev in Lisp a joke?
Anonymous · 2020-01-11 19:49
>>16514 No. (defparameter *app* (make-instance '<app>)) @route GET "/" (defun index () (render #P"index.tmpl")) http://8arrow.org/caveman/ https://lispcookbook.github.io/cl-cookbook/web.html https://lisp-journey.gitlab.io/web-dev/
Joe Bloggs · 2020-01-14 17:59
The real joke is being so out of touch that you think webdev can't be done on some language that doesn't have a popular webshit framework.
Boris Grishenko · 2020-01-15 10:00
Hi there lainons. Mods: If this is off-topic, feel free to delete posts. But I think this is the right place to ask my question. I am going to e-beg a little. Do any of you have made public a stumpwm configuration? I am using Ubuntu in my work laptop. When upgraded to 19.10, gome got all fuarrrked up. I dont feel like installing a full DE, so I dabbled with both DWM and Stumpwm. DWM is working fine, but I dont like how it interacts with emacs + I dont know any C. But for me, yes for me, and probably me only, Stumpwm is barely usable outo of the box.
tadni · 2020-01-19 06:26
>>16558 Nah, Stumpwm is only meh by default I'd agree. The project wiki has a few linked via https://github.com/stumpwm/stumpwm/wiki/Customize Here's also mine from years ago (https://raw.githubusercontent.com/tadni/config/bc629bfb3a439f303da9961b86f174f7eb5432ee/program/wm/stumpwm/init.lisp), that I plan to finally start updating again soon. The modules are commented out because I couldn't get them working on a 'modern distro' / setup. But you can probably get the idea based on the bottom bar. Also my prefix key is remapped to Ctrl+' and iirc Ctrl+' ? will bring up a list of commands. License is EPLv2 if you plan to upload / distribute edited version anywhere.
fsociety · 2020-01-20 11:39
>>16616 Thanks a lot! Unfortunately, the link you provide to your config is yielding a 404 response. I will check the project configs.
Boris Grishenko · 2020-01-22 04:29
Anyone want to critique my simple 2 player rock-paper-scissors program? It was part of an exercise regarding conditionals. lisp (defun rps (p1 p2) (cond ((and (equal p1 'scissors) (equal p2 'rock)) 'p2-wins) ((and (equal p1 'scissors) (equal p2 'paper)) 'p1-wins) ((and (equal p1 'rock) (equal p2 'scissors)) 'p1-wins) ((and (equal p1 'rock) (equal p2 'paper)) 'p2-wins) ((and (equal p1 'paper) (equal p2 'scissors)) 'p2-wins) ((and (equal p1 'paper) (equal p2 'rock)) 'p1-wins) ((equal p1 p2) 'draw) (t 'not-sure-what-you-typed))) The solution in the book I'm reading seemed too hacky for my liking though I'm not sure if what I wrote is bad cl practice. I'm not very familiar with the language and with programming in general.
(princ tripcode) -| · 2020-01-22 07:28
>>16558 My configuration isn't public, for no reason, but I'll share some parts of it; the remainder is rather specific to my setup and handles having the mode-line show volume, battery, etc. and I've also several bindings for launching programs my way; note that the volume buttons break under my setup temporarily, because the sink changes for no reason, and so this code is best-suited to being changed to the particulars of your system, because every system must have its own way to do something so simple; the volume collection code for the mode-line is terrible and wasteful, and yet it runs every second: (setq *input-history-ignore-duplicates* t *normal-border-width* 0 *window-border-style* :thin *mode-line-position* :bottom *mode-line-timeout* 1 *timeout-wait* 30) (define-key *root-map* (kbd "`") "exec xset dpms force off; slock") (define-key *root-map* (kbd "~") "exec sleep 0.25; xset dpms force off") (define-key *top-map* (kbd "SunPrint_Screen") "exec scrot --quality 100") (define-key *top-map* (kbd "XF86AudioRaiseVolume") "exec pactl -- set-sink-volume 1 +5%") (define-key *top-map* (kbd "XF86AudioLowerVolume") "exec pactl -- set-sink-volume 1 -5%") (define-key *top-map* (kbd "XF86AudioMute") "exec pactl -- set-sink-mute 1 toggle") (toggle-mode-line (current-screen) (current-head)) >>16642 >Anyone want to critique my simple 2 player rock-paper-scissors program? Yes. Your program is unnecessarily repetitive. It's unfortunate the CASE macro isn't suited to solving this nicely. I've written a similar program, my way, and I'd advise you to observe how I've done so; note that the ELT array drives control flow implicitly and note how I avoid your NOT-SURE-WHAT-YOU-TYPED case: (defun rock-paper-scissors (first second &aux (elt #(:scissors :paper :rock :scissors))) (check-type first #0=(member :scissors :paper :rock)) (check-type second #0#) (if (eq first second) :draw (if (eq second (svref elt (1+ (position first elt :test 'eq)))) :first-wins :second-wins))) >The solution in the book I'm reading seemed too hacky for my liking though I'm not sure if what I wrote is bad cl practice. I'm not very familiar with the language and with programming in general. It's not bad, considering you're a novice. I've not tested it, but it looks like it works. I was having a discussion just recently in which I discussed how it's not enough for a program to work correctly, however, as that's the barest minimum standard; a program should work correctly and do so well, with the program itself being nicely written and amenable to change. Your P1-WINS and P2-WINS cases aren't organized, which is poor form. You seem to properly grasp how to write basic programs, so you're not doing poorly for yourself, I'd write. Continue on with your reading and practicing; which book are you reading?
Emmanuel · 2020-01-23 08:23
>>16558 StumpWM, at least for me, is about hacking together a system that works for you, rather than getting a particular experience out of the box. Though, that's part of the reason I don't use it anymore. (I've switched to dwm, funnily enough.) Keep tinkering, the source is mostly easy to understand even if it is a mess and it's great fun to run your WM on Lisp. Here's a nice function to select any window across groups/desktops. Embarrassingly, I can't say where I found it, only that I didn't write it myself. (defcommand vwinlist () (:rest) (let* ((g (current-group)) (frames (group-frames g)) (selection (second (select-from-menu (current-screen) (mapcan (lambda (f) (list* (list (format-expand *frame-formatters* *frame-format* f) f) (mapcar (lambda (w) (list (format-expand *window-formatters* (concatenate 'string " " *window-format*) w) w)) (sort-windows-by-number (frame-windows g f))))) frames) nil)))) (if selection (typecase selection (frame (focus-frame g selection)) (window (progn (switch-to-group (window-group selection)) (group-focus-window g selection)))) (throw 'error :abort)))) Also note that you can assign keys to *top-map* under a modifier like super if you don't like the concept of a leader key. Attached is also a patch for dwm that allows specified windows to request and steal focus on the same desktop since Emacs frames rely on this behaviour. I don't know if that was your particular issue, but it was mine when I switched.
setq · 2020-01-23 12:08
>>16643 >and note how I avoid your NOT-SURE-WHAT-YOU-TYPED case Yeah, it's much cleaner and it's not prone to bugs. After I made my post I've noticed in my code that if you type two same strings, regardless of what they are as long as they're same, the program will return "draw". check-type seems to eliminate such mistakes, though I'll be honest I haven't encountered that macro before. >You seem to properly grasp how to write basic programs, so you're not doing poorly for yourself, I'd write. Continue on with your reading and practicing; which book are you reading? Thanks for the words of encouragement and the book in question is "A Gentle Introduction to Symbolic Computation" the 2013 edition.
drop · 2020-01-26 12:12
I've recently been studying some very minimal Scheme interpreters in order to understand how they function, and, hopefully create my own. (I have very little understanding of interpreters in general.) One of those that I've been studying is the famous minischeme ( https://github.com/catseye/minischeme ), another is this intentionally simple learning project by Peter Michaux ( https://github.com/petermichaux/bootstrap-scheme ), both of these are using the simple "Tree walking" method, i.e. not converting the Scheme code into some sort of intermediate representation. (at least, if I'm understanding them correctly). But one thing that I find strange about minischeme is that it expresses a lot of it's functionality in terms of what looks like some sort of a "machine" with registers and operations with their opcodes and a kind of dispatch table (Eval has it's opcode, so do apply, load, read, lambda, and so on). Whereas Michaux's project does it in terms of simply C functions, doing the eval-ing, applying, and everything else. Again, both of them aren't bytecode interpreters or anything like that, but is there a name for this type of interpreter, like minischeme, where it seems to almost be emulating some sort of a machine, are there benefits to this approach, or drawbacks. Obviously, there's a world of difference between these two, but I'm just focusing on this one thing.
Mitnick · 2020-01-28 03:28
I've been interested in writing a kind of modern clone of Symbolic Genera, probably using Chez Scheme (as that's my favorite Lisp dialect). No real question, just a statement of something I'd like to try. Would love any resources people have on how to approach that - my main plan was to read the source on other simple OS (like TempleOS) & build up from there. Obviously I'd be needing to target x86 rather than a Lisp machine, but still - could be cool to have.
null · 2020-01-29 20:25
>>15857 How do I make a post request with a file in racket?
Elliot Alderson · 2020-01-31 08:18
What are easy ways to view function definitions in Guile Scheme? Preferably without having to use Emacs.
Cereal Killer · 2020-01-31 18:33
>>16707 https://docs.racket-lang.org/http/index.html#%28def._%28%28lib._http%2Frequest..rkt%29._start-request%29%29
DEBUG-CONTENTS · 2020-01-31 21:12
What am I doing wrong here lainons? It keeps telling me unbalanced close parentheses but I've triple checked and they all balance. Very confused (define (fb-loop num) (cond ((= (modulo num 3) 0) (display 'fizz')) ((= (modulo num 5) 0) (display 'buzz'))) (newline)) (fb-loop 100)
Donna Hawthorne · 2020-01-31 22:20
>>16720 'fizz' is not a string. it's a symbol followed by a syntax error. Scheme strings use double quotes.
Anonymous · 2020-01-31 22:56
>>16721 Thank you I feel retarded now bless you lainon
Cereal Killer · 2020-02-01 00:17
Bully my code lainons, 4ch/g/ seems to think there's something inherently wrong with it (define (fb-loop num) (if (= (modulo num 3) 0) (display "fizz")) (if (= (modulo num 5) 0) (display "buzz")) (if (= (modulo num 6) 0) (display "fuzz")) (if (not (= (modulo num 6) 0) (= (modulo num 5) 0) (= (modulo num 3) 0)) (display num)) (newline) (if (< num 100) (fb-loop (+ num 1))) 0) (fb-loop 0)
array · 2020-02-01 18:31
>>16724 Firstly, the program will not even run because you are using not wrong, as it does not take more than one argument. I think you meant (not (or ...)) . What is the point of returning 0? I actually answered a similar question to this on /g/ a few days ago. The main problem here is that you need to think more lispy about the problem. The nature of your code is very procedural and doesn't really take advantage lisps unique features like lists, lambdas or symbols. It would be an alright solution in something like C, but not so much in a functional language like lisp. My fizzbuzz in scheme would be something like this: (define (fizzbuzz r) (map (lambda (n) (cond ((= (modulo n 3) (modulo n 5) 0) 'fizzbuzz) ((= (modulo n 3) 0) 'fizz) ((= (modulo n 5) 0) 'buzz) (else n))) (cdr (iota r)))) (fizzbuzz 100) Returning results as lists in scheme is great because you can do further operations on them like (filter number? (fizzbuzz 100)) if you, for example, only wanted the numbers of the solution for some reason. Lisp is all about lists!
Faye Valentine · 2020-02-02 01:06
>>16727 Thank you for the constructive input lainon! 4/g/ seems to be full of memesters that just I am angry when they see something they don't like. I'm going to go through SICP again and maybe finish it this time, hopefully it'll make me a better Scheme writer.
Joe Bloggs · 2020-02-02 01:53
>>16730 No problem anon. /g/ is generally pretty bad unfortunately. I think a good rule of thumb for functional programming is aiming at writing procedures that "only do one thing". Like how my fizzbuzz is actually only a map function. If you look at the definitions of the powerful eval and apply procedures in SICP you will see that even they are just a cond clause. This is why return values in lisp are implicit.
⍕ · 2020-02-02 03:04
>>16732 I used to browse 8chan/tech/ in the day as well as this place but 8chan has been dead for a long time, unfortunately. Do you have any other tech-centric boards/chans I could browse? All I know that is still active is here and 4ch/g/
Leto Atreides I · 2020-02-02 20:30
>>16724 i think that returning zero at the end like that will prevent tail call optimization
Otto Normalverbraucher · 2020-02-04 00:24
I decided to try and write a restful client in LISP to make automated changes to a static webserver remotely. lisp (defun session (uname pword f) (flet (; get auth token via some unknown api call (get-token (uname pword) 'buz)) (let ((token (get-token uname pword))) ; passing token to f authorizes f to change our website (funcall f token) ; logout by deleting client-side auth token (setf token '())))) ; example usage (session 'foo 'bar (lambda (token) (loop for i below 23 do (print (list i token))))) This is designed to work with neocities specifically right now, but it's still abstract enough that I could easily rejigger it to work with any restful API. Going to implement the actual neocities interface later.
Hagbard Celine · 2020-02-04 00:42
>>16736 No, it doesn't.
setq · 2020-02-04 02:46
>>16746 Why not?
Knuth · 2020-02-04 03:01
>>16748 The recursive fb-loop call is a tail call because the result of its evaluation is not used in its environment. There's nothing in the environment that is waiting for fb-loop to finish. So it could be tail-call optimized.
drop · 2020-02-04 03:55
>>16749 Ah, just like this function's recursive call is a tail call because the result of its evaluation is not used in the environment? (define (fb-loop-2 num) (if (= (modulo num 3) 0) (display "fizz")) (if (= (modulo num 5) 0) (display "buzz")) (if (= (modulo num 6) 0) (display "fuzz")) (if (not (= (modulo num 6) 0) (= (modulo num 5) 0) (= (modulo num 3) 0)) (display num)) (newline) (if (< num 100) (fb-loop-2 (+ num 1))) (display 0)) (fb-loop-2 0)
Boris Grishenko · 2020-02-04 04:07
>>16724 You want to separate the iteration and the conversion. (defun fizzbuzz-convert (n) (cond ((zerop (mod n 15)) 'fizzbuzz) ((zerop (mod n 3)) 'fizz) ((zerop (mod n 5)) 'buzz) (t n))) (loop for n below 100 do (print (fizzbuzz-convert n))) >>16727 >but not so much in a functional language like lisp. Lisp is not a functional programming language. https://letoverlambda.com/index.cl/guest/chap5.html#sec_1
Hououin Kyouma · 2020-02-04 04:54
>>16750 Yep pretty much
cdr · 2020-02-04 04:56
Why is CLISP documentation such complete and utter soykafe? I have been trying to install a library for over 4 hours now.
Anonymous · 2020-02-04 05:05
same guy from >>16753 I can run quicklisp from the REPL, but when I just run my program non-interactively, suddenly lisp can't find quicklisp anymore. Is there a way to run CLISP non-interactively so that it loads my clisprc before trying to run or compile my code?
limited · 2020-02-04 05:10
>>16754 Nevermind. I called CLISP with the -i option and fed it my .clisprc
Anonymous · 2020-02-04 06:36
>>16752 Guile does not generate a tail call for the version of the function with a trailing expression after the recursive call. (define (fb-loop num) (if (= (modulo num 3) 0) (display "fizz")) (if (= (modulo num 5) 0) (display "buzz")) (if (= (modulo num 6) 0) (display "fuzz")) (if (not (or (= (modulo num 6) 0) (= (modulo num 5) 0) (= (modulo num 3) 0))) (display num)) (newline) (if (< num 100) (fb-loop (+ num 1))) 0) (define (fb-loop-3 num) (if (= (modulo num 3) 0) (display "fizz")) (if (= (modulo num 5) 0) (display "buzz")) (if (= (modulo num 6) 0) (display "fuzz")) (if (not (or (= (modulo num 6) 0) (= (modulo num 5) 0) (= (modulo num 3) 0))) (display num)) (newline) (if (< num 100) (fb-loop-3 (+ num 1)) 0)) Enter `,help' for help. scheme@(guile-user)> (load "guile-test.scm") scheme@(guile-user)> ,disassemble fb-loop Disassembly of #<procedure fb-loop (num)>: ... scheme@(guile-user)> ,disassemble fb-loop-3 Disassembly of #<procedure fb-loop-3 (num)>: 210 (tail-call 1) at /home/anon/guile-test.scm:18:6 scheme@(guile-user)> https://www.gnu.org/software/guile/docs/master/guile.html/Call-and-Return-Instructions.html
Morpheus · 2020-02-04 06:44
>>16753 >>16754 >>16755 A three part drama Library won't work today. Silence from the crowd
Miho Iwakura · 2020-02-04 10:53
>>16758 And now she takes a minute to run every time I want to test my code. I have a lot to learn still. >>16757 There are a lot of nitty gritty details that have to be resolved whenever one is implementing something like tail recursion, not all lisps will behave exactly the same way. I think in R5RS both function calls would be tail recursive.
Mario Rossi · 2020-02-04 15:25
>>16762 >I think in R5RS both function calls would be tail recursive. No, only the latter function uses a tail call according to R5RS. https://schemers.org/Documents/Standards/R5RS/HTML/
Leto Atreides I · 2020-02-04 15:27
>>16763 I copied over the wrong link. Here's the link to the relevant section. https://schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-6.html#%_sec_3.5
dup · 2020-02-04 15:37
>>16762 >nitty gritty details there's nothing "nitty" or "gritty" about this. The 0 has no purpose, makes no sense, and is the final expression so it and not a recursive call is in the tail position, so no recursive call can be a tail call. TCO is a very simple and easy to understand code transformation, which is why it can be guaranteed behavior in Scheme.
stack · 2020-02-04 17:12
>>16764 >>16765 Also from the r5rs standard linked earlier: >Implementations are allowed, but not required, to recognize that some non-tail calls, such as the call to h above, can be evaluated as though they were tail calls. Sounds implementation-dependent to me.
() · 2020-02-04 17:13
Forgot the image
Jane Doe · 2020-02-04 17:20
>>16765 I didnt notice that the zero has to be unconditionally evaluated because it is outside of an if clause. You're right, that soykafs all fuarrrked up.
Acid Burn · 2020-02-04 18:04
>>16768 Who NEEDS TCO to make their program work? People working with tiny RAM maybe?
Mentat · 2020-02-04 19:34
Can you not compile to standalone binaries with chez scheme? I can compile with compile-file but the resulting binary still needs chez to run. If not, what are the best alternative implementations?
↑ · 2020-02-04 21:02
>>16774 I found gwatt/chez-exe repo on github: Looks like they embed the chez scheme system into an executable along with your program. This becomes problematic in cases like Proton, where they create standalone binaries by embedding google chrome, and then people end up with 20 copies of google chrome all running on their systems. I often wonder: are there technologies that can automatically detect these embedded apps and force them to share a single runtime?
t · 2020-02-10 04:08
Are there any good style guides for Common Lisp? I've been getting into the language recently and my code is still unreadable nonsense.
if · 2020-02-10 06:11
>>16837 You don't really need a style guide, but this seems okay. https://lisp-lang.org/style-guide/ Google used to have one too, but it seems to be down.
(princ tripcode) -| · 2020-02-11 02:14
>>16775 >I often wonder: are there technologies that can automatically detect these embedded apps and force them to share a single runtime? You may be interested to know Multics had a segmented memory system which maintained single copies of programs, files, and like things in memory. It required cooperation, compared to this problem, however. Considering the grotesque sizes of these programs, scanning four kilobyte pages to detect identical copies would likely be prohibitively expensive, and so we see something simple be considered intractable. >>16837 You've given me the idea of writing my own Common Lisp style guide, considering I've a dearth of writing ideas, currently. If I write one, would you be interested in reading it?
Lukasiewicz · 2020-02-11 02:38
>>16841 Not the person that you're replying to but yes, I would be interested.
Project 2501 · 2020-02-11 15:52
>>16841 I am the person you were replying to, and I'd be very interested.
藤原純一 · 2020-02-12 17:07
>>16864 >>16861 >>16846 Thus accounts were created, lol. On-topic is there any suggestions for saving a big tree data structure persistently in common lisp web application? What I want to do is have a big tree and by querying for a node get it's path all the way to root. Each element of the tree will have a single ancestor and multiple children, so I don't think querying will have to be that intensive. The thing is that the nodes can easily go in order of millions and I'm looking for something that can be handled in a single computer. I think a NoSQL database would be of use in this but are there other suggestions? The application would be mostly read-heavy.
Hitomi · 2020-02-13 11:29
>>16877 You can build the path as you search the tree for the node. Otherwise, you can also include information about the data to the left and right of each node, in the node, sort of like pic related, but I guess upside down in your case? Like the nodes towards the leaves will contain more information than the nodes closer to the root?
(princ tripcode) -| · 2020-02-15 05:04
>>16841 >>16843 >>16846 This is a first draft of sorts: http://verisimilitudes.net/2020-02-14 gopher://verisimilitudes.net/02020-02-14 It would be too long if I documented every thought related to Common Lisp. In any case, you can help me improve this document by giving your thoughts and letting me know if you believe I've failed to mention anything you find important.
recursion without exit · 2020-02-17 17:17
Guys, why do we like lisp?
Turner · 2020-02-17 18:22
>>16934 It's got a very clean and simple syntax that's easy to learn, never gets in the way, and results in code that's easy to write and even easier to read. Learning Lisp, for me, was a very similar experience to HTML. I read up on the overall syntax exactly once, and spent the rest of my time figuring out what individual functions did.
Just another Random Lainon · 2020-02-17 20:40
>>16934 Interactive development Beautiful Syntax POWER
Nobody important · 2020-02-18 00:32
>>16934 Lain uses it.
Hououin Kyouma · 2020-02-19 02:29
>>16923 Don't have much to add, just wanted to say that I find it a bit odd that you don't use other peoples libraries.
protected · 2020-02-19 04:16
>>16923 This is well written, but any style guide is a giant target for anonymous criticism. So here I go. There is zero reason to avoid 'when' and 'unless' except for avoiding side effects, mutation and IO, in general. Also (SETF NUMBER 0 INTEGER (1+ NUMBER) STRING (PRINC-TO-STRING INTEGER)) (SETF NUMBER 0 STRING (PRINC-TO-STRING (INCF INTEGER)))
(princ tripcode) -| · 2020-02-19 05:46
I've just added to this stye document, at the end explaining how I think macroexpansions should be and also clarifying near the beginning of the document that the examples are in uppercase for stylistic purposes only and so not as part of the suggested style, as this confused another reader. >>16960 >Don't have much to add, just wanted to say that I find it a bit odd that you don't use other peoples libraries. I could dedicate an article to that topic alone; I should probably start collecting ideas on it. The basic idea is I mostly work alone out of necessity. If I'm already going to implement most of a program myself, because I either don't like the libraries available or they don't exist, why wouldn't I just write the little pieces I do need myself? Not only this, but it's also educational to do so and so expand my expertise and knowledge. I could work with others on some large project, but I don't really have the opportunity, and it would mostly be a bother if someone wanted to contribute to my libraries; I'd lose the ability to call them my sole work, relicense them if I want, among other things. I believe if I were going to work with others, I'd probably find myself contributing on a systems boundary, where a library is needed, say, and so I write it, but having complete control over it and that being my helping. >>16961 >This is well written, but any style guide is a giant target for anonymous criticism. So here I go. I appreciate the thoughts and the compliment; writing it took me just a few hours on the day it was published. Once I let it sit for a few more days, I'll have the WWW version formatted as HTML. >There is zero reason to avoid 'when' and 'unless' except for avoiding side effects, mutation and IO, in general. I've simply never felt compelled to use either over the alternatives, so I don't. That's a nice transformation you made there. I considered using a set of false functions, but decided on real such functions, instead. The point of course was that you should always prefer to use an appropriate form, INCF, SVREF, etc., unless you can get better code with a minor concession.
H.R. Giger · 2020-02-19 07:02
>>16963 Wait so have you implemented HTTP yourself?
(princ tripcode) -| · 2020-02-19 08:06
>>16964 I've not written an HTTP client myself, no. If I needed to write a Common Lisp program that interacted with HTTP, I'd try to make it operate on discrete messages or streams, largely freeing me from the need to interact with HTTP itself or the library, varying on the particular problem. I've actually used Drakma a tad and I've a few ideas on how I'd design differently, but I'm not denigrating Drakma with this; one thing noticeable about Drakma is how many libraries it uses, with one being a binding to OpenSSL, if I'm recalling correctly, and all of this makes it arduous to load. By the by, I should've explicitly mentioned in my previous post that I'd be interested in considering working with anyone here, if they wanted my assistance. I won't promise interest on my part and my helping could be anything from intimate working on the same code to writing a library, but feel free to ask, in any case.
Tomohisa "Tom" Kanezaki · 2020-02-19 15:41
>>16963 >The point of course was that you should always prefer to use an appropriate form, INCF, SVREF, etc., unless you can get better code with a minor concession. Since we're talking about specific forms in assignment, PSETF and ROTATEF are very useful.
Chan Siu Ming · 2020-02-19 15:43
>>16970 Also SORTF if you're Doug Hoyte.
Wilson · 2020-02-23 22:16
Graphviz is fun and LandOfLisp is a great textbook. I like how the author outlines a basic spec before every project, so I can put the book down and try to do the whole implementation myself before reading how he did it.
Sabo Engle · 2020-02-27 09:14
So what Lisp are you working on? Is anyone working on the thread challenge, perhaps? I'm continuing my work towards a comprehensive SHA library, and the CLOS design I've thought of is going well so far, but I've yet to read about the SHA-3 family in detail, so I don't know how well my design will accomodate it, but not researching beforehand will certainly stress test my design's flexibility.
quote · 2020-02-27 12:52
>>17018 It's indeed great fun, but I found the programming style in the book to be very idiosyncratic. I don't think I've seen anyone use symbols like the author does before or since. I guess that's the problem with Lisp, it's so versatile that anyone is free to write programs in whatever weird way he wants.
John Titor · 2020-02-27 23:01
>>17134 You mean building strings out of symbol lists? Do you have examples?
limited · 2020-02-28 10:45
>>17141 I'm a different poster, but I've also taken a look at the book before and found this stood out. You can find examples like this from older Lisp programs, too: (princ '|This behaves like a string.|) (princ '(this does not look as nice))
Donna Hawthorne · 2020-02-29 02:59
>get an idea for a small programming challenge >translate arabic numerals into roman numerals >find out you can do this with format ~@R~% is there something that this language can't do?
if · 2020-02-29 08:49
>>17156 No. It's turing complete.
Lain Iwakura · 2020-02-29 08:52
>>17156 Though, a more difficult challenge might be to transliterate arabic letters with or without diacritics, into roman letters. I bet you'll learn a lot about unicode.
Six · 2020-02-29 09:09
>>17161 Deterministic turing complete. It cannot solve problems that require other classes of turing machine.
Chani · 2020-03-03 02:30
Are there any GUI toolkit bindings for Common Lisp that are both maintained and also good?
Unnamed · 2020-03-03 02:59
>>17206 The only one I'm aware of is CAPI: http://www.lispworks.com/products/capi.html Unfortunately, it's proprietary. Both of GTK and Qt seem complicated and the only Qt binding I'm aware of isn't using the latest version; I believe GTK is even worse off here. Everything else is either incomplete or weird. There's plenty of libraries that pretend they're useful and end up just being Electron. I wouldn't blame this mess on Common Lisp, though, but the surrounding environment. It's entirely a mess, to the point groups are using a damn web browser for it.
Dr. X · 2020-03-04 16:25
>>15903 I have the same doubt as you do, anon. I don't know if I should take Guile or Common Lisp as my first lisp. What are your thoughts, anons?
drop · 2020-03-04 18:23
>>17216 Not a guile user, but I have been making a transition from R5RS scheme (gimp y'know?) to common lisp, and I like common lisp. It was hard to wrap my head around at first, because Common Lisp has waaaaaay more primitives than scheme. At first I found this annoying, because common lisp documentation kinda is like kicking dead whales down the beach. Now I'm into it though. I think the large library is convenient.
stack · 2020-03-06 00:33
What resources does lain use for ANSI Common Lisp documentation? So far I just use Land of Lisp as a reference, but the examples in the book are extremely limited, as its only an introductory text. CLHS consistently pops up at the top of my search results but I don't understand enough CL to be able to use it, and i can't figure out how to use it to fill in those gaps in my understanding which make it unusable to me. Is there another dialect of Common Lisp with better documentation? Would switching to SBCL help?
Apoc · 2020-03-06 04:56
>>17233 CLHS is fine to reference things. It only looks scary. Just scroll down to the examples. (describe #'describe)
Motoko Kusanagi · 2020-03-06 06:48
>>17235 They don't cover the things that I'm trying to do im the examples very often. What really trips me up are the keyword parameters.
Unnamed · 2020-03-07 01:20
>>17233 >What resources does lain use for ANSI Common Lisp documentation? I use SLIME in Emacs. If the minibuffer lambda list isn't enough I use C-c C-d C-d, slime-describe-symbol, and this gives the information DESCRIBE and DOCUMENTATION give. I'll use my recall and the standard functions to get myself out of the majority of issues; once you use Common Lisp long enough, you recall enough patterns to APROPOS and think your way out of most of the issues. The value of MACROEXPAND-1 also shouldn't be understated. If these fail me, I use the HyperSpec or ANSI Common Lisp, usually the former, and that's usually the end of it. Having an intuitive knowledge of the language goes a long ways. >Is there another dialect of Common Lisp with better documentation? It's a good idea to have SBCL, ECL, Clisp, and any other implementations available. >Would switching to SBCL help? It may. Some people may treat SBCL as if it's a dialect of Common Lisp, but this is poor. Clisp is a good implementation for those getting accustomed to the language, even without a more advanced environment setup, so perhaps give that a try.
Masami Eiri · 2020-03-09 23:14
Hello prince trippy
(princ tripcode) -| · 2020-03-09 23:38
>>17305 Hello. Is there anything you wanted to ask me in particular? As is rather obvious here, that pseudonym was derived from this name I'm using now.
Batou · 2020-03-13 22:46
Hello, do Scheme questions belong here? I would like to ask laiton to share some resources so I can learn more about (syntax-case) and (syntax-rules) in R6RS and R7RS respectively, and how is the equivalence between them. My purpose is to port an R6RS library to R7RS, and said library makes use of (syntax-case) which is not included in R7RS.
protected · 2020-03-30 03:16
Going through "A Gentle Introduction to Symbolic Computation" and I banged my head against the wall until a couple of minutes ago because one of the exercises was somewhat frustrating. I had to define a function called "alloddp" which returns either T if all elements of the list are odd or NIL if all of the elements are even. I'm on the chapter covering recursion so I had to do this recursively. I was able to tinker and came up with the solution which is: lisp (defun alloddp (x) (cond ((null x) t) ((evenp (first x)) nil) (t (alloddp (rest x))))) However I was banging my head against the wall because I wasn't able to understand the behavior quite completely. Prior to this the book showed my how to make a function called anyoddp which looks if there's any odd characters in the list, the code for that is: lisp (defun anyoddp (x) (cond ((null x) nil) ((oddp (first x)) t) (t (anyoddp (rest x))))) The part which confused me the most in the "alloddp" function was the first clause of cond. I assumed that this behavior is wrong and that it should be ((null x) nil) like in the other function because I thought that clause was there only for terminating. And it is but I didn't quite get that it terminates like this because it goes through the whole x list and compares the cdr of last with null which returns t. All in all I'm proud of myself for this realization even if it took me a couple of hours to really understand what's going on. Sorry if I'm rambling too much, just wanted to share this cool realization with other lainons. P.S. The downside of this is that you can enter an empty list and get t but alas, I've checked the solution in the book and it's the same as mine.
Y.T · 2020-03-30 07:11
>>17608 Your ALLODDP seems fine and you meant to write or NIL if any of the elements are even. The reason it's T for the empty list is not only for a ground case to cease recursing, but also as the identity, no different from (+) being zero or (*) being one. Your ANYODDP is also fine. The reason the ground case differs here is because rather than being certain of the answer when you can no longer find numbers which aren't odd, it's instead that you've failed to find a number which is. Since you're looking for any odd number, it's NIL if you can't, as that identity.
Koos van der Merwe · 2020-03-31 03:01
>>17617 >you meant to write or NIL if any of the elements are even. I did! Sorry, my mistake. >The reason it's T for the empty list is not only for a ground case to cease recursing, but also as the identity, no different from (+) being zero or (*) being one. >The reason the ground case differs here is because rather than being certain of the answer when you can no longer find numbers which aren't odd, it's instead that you've failed to find a number which is. Since you're looking for any odd number, it's NIL if you can't, as that identity. That's rather interesting, thank you for your input.
Lain Iwakura · 2020-04-01 07:46
I found a (prose) book that's source is in a Racket lang called Pollen. https://github.com/treeman/why_cryptocurrencies https://docs.racket-lang.org/pollen/ If you want to read the book, visit: https://whycryptocurrencies.com/
Dr. X · 2020-04-01 18:15
Hi, i'm new to LISP (i only know Scheme so far) I was wondering how one would draw some graphical output, i wan't to plot some values in a coordinate system. Is LISP any good for this or should i just use something like R ?
Tank · 2020-04-01 23:34
>>17666 R is pretty good for that, but you can do it with various lisps too. With Racket, you could try: https://docs.racket-lang.org/plot/intro.html
DEBUG-CONTENTS · 2020-04-01 23:56
>>17666 R is like kicking dead whales down the beach just use python or Matlab if you want it easy
Agent Smith · 2020-04-02 22:38
>>17675 Care to justify your answer in a thread where it is not offtopic?
(princ tripcode) -| · 2020-04-03 08:03
>>17666 Have you considered feeding plotting commands to GNU plot: https://www.gnu.org/software/plotutils >>17133 So I'm still working on this. I believe my design could accomodate the SHA-3 family, but I know it would be better to have specialized machinery for it. I'm mostly thinking about the organization right now. The package is designed to always be used with the package prefix, and I think it would look better with a separate SHA3 package. It's the difference between the following two: (SHA:HASH SHA:3-512 ...) (SHA3:HASH SHA3:512 ...) I prefer the latter, and I'll probably go with that design decision, which may also make it easier to expose specialized SHA3 features the remainder lack, but I thought I'd ask what you think, in any case. I'd be interested to read what you're working on. I've been intending to read some documentation and start writing Common Lisp tools for some data formats. I'm going to try to at least start my own implementation of LOOP this month.
Davis · 2020-04-03 18:40
>>17690 Apologies. I never liked R, everything I did on it I could do in Python, apart from hardcore statistics stuff, which I doubt you want. Much better to learn to use Python properly even if it may be easier to do some basic plots. Matlab (if you can get it for free) is more like a calculator but if you want nice plots easily it is unrivalled, it is made for linear algebra. If you want pure ease use Matlab don't waste time with R, if you don't need ease that much use python, because with some expertise you can make it run faster than Matlab. I just don't really see any use case outside of statistics where R is superior
Iverson · 2020-04-05 06:37
Does anybody here have some experience with janet?, seems pretty neat and fits into >>16021 aswell.
Batou · 2020-04-05 20:39
>>17706 Julia or SciPy seem like the better alternatives to R, from what I've heard from friends who work with it. There are some cool tools for Lisp if you just want to use it for experimentation though: https://cliki.net/Mathematics
藤原純一 · 2020-04-05 22:34
Wrote the garbage weather ticker for Stumpwm's modeline back in the day. Totally reworked it, no dependencies on external scripts, more configurable, less fragile https://gitlab.com/riley/swm-weather/ Also wrote something to make life at work easier https://gitlab.com/riley/swm-nagios/ Little nagios ticker for the mode-line since I do sysadmin work Both require a threaded lisp to avoid a long web-request or timeout from hanging your UI every time they try to fetch new information. If you've got critiques, I'd be glad to hear them. I don't get nearly as much time to do any programming these days, let alone time to program in Lisp
dictionary · 2020-04-06 01:33
I've really been enjoying Racket at the moment, but it feels so wild programming without types, I don't know how you lot do it. Need to pick up typed racket and hopefully that'll help a bit, really wanna get good at macro wizardry
byte · 2020-04-06 04:50
>>17765 Whats typed racket? How would that even work?
cdr · 2020-04-06 22:42
My local scala meetup group has opened a call for talks. I thought it could be a nice lisp evangelization oportunity and I might approach them with a clojure intro. What topics do you think should be covered that would interest that kind of crowd? I was thinking either proposing them a more intro to functional programming or a more indepth intro to clojure. What are your takes? What ecosystem would you guys give the talk in? I was thinking a dockerized emacs with org-babel running, using it kinda like a python notebook. But maybe that would put them off, cause some people have this extreme emacs hate. On the other hand, I cannot imagine lisping arround without paredit.
Mentat · 2020-04-07 01:50
>>17768 > Typed Racket is Racket’s gradually-typed sister language which allows the incremental addition of statically-checked type annotations. https://docs.racket-lang.org/ts-guide/
hash table · 2020-04-07 01:52
>>17770 >I cannot imagine lisping arround without paredit. Bring them into your world.
Roy Batty · 2020-04-09 20:24
Is there a guide on how to build simple LISP interpreters? I don't have a clue on how or where to start.
Cereal Killer · 2020-04-10 01:23
Should I learn Lisp instead of Haskell? I am looking for a programming language that can give me opportunity in discovering functional programming. What kind of lisp should I chose for this?
JARGON · 2020-04-10 12:42
>>17795 I would say depends on whether you like typing or not. I started programming in Python, and Haskell (and the ml family in general) took a while to click, while I felt at home with lisps. For my colleagues coming from Java, the reverse was true. Scheme and clojure are more functionally opinionated than common lisp. I find clojure's Java interior quite useful, and reading sicp is a great way to learn some scheme, functional programming and some CS theory. But at the end of the day, what do you want to accomplish? Just learning, signaling in your cv... Just pick the most appealing to your use case, you cannot go wrong and there is a huge overlap between these languages, in case you feel like you need to pivot in the future.
nil · 2020-04-11 00:03
>>17800 I wanna understand functional concepts such as functors, monads and find out how can I use them in production.
cdr · 2020-04-11 19:39
>>17804 If you want to learn that kind of stuff, you'd be better off using a language where monads are part of their culture and used all the time. I don't think there's a lisp that meets that criteria. Monad implementations may exist in various lisps, but they're not heavily used and it's not idiomatic.
Project 2501 · 2020-04-11 19:42
>>17791 read-eval-print-loop repl https://kanaka.github.io/lambdaconf/#/
Elliot Alderson · 2020-04-12 23:52
>>17791 Start by defining the fundamental functions and types, like EVAL. Once you have lists, can READ them in, and then EVAL them, you have a very basic interpreter. >>17795 >>17804 I've never used Shen, but you should give it a look: http://marktarver.com http://www.shenlanguage.org Now for my question. I'm writing a program using CLOS and want to speed it up by avoiding dispatch where feasible; isn't this something COMPUTE-APPLICABLE-METHODS can be used for? It's one of those queer local macros and I'm having issues using it and then actually using the list of methods it returns; I thought I'd ask here rather than skulking around elsewhere. I can continue with my work and tack it on later, anyway.
Hououin Kyouma · 2020-04-12 23:56
>>17858 My mistake, COMPUTE-APPLICABLE-METHODS is a normal generic function and it's CALL-METHOD and friends which are those queer local forms.
Crazy Jake · 2020-04-13 13:06
>>17804 >>17814 Yeah, I dont think lisp is the right thing for you then. I think haskell or scala are more what you are looking for.
queue · 2020-04-13 13:12
>>17791 I am currently working through build your own lisp[0], which is a C tutorial, but the common topic is, you guessed it right, building a lisp. It might be helpful to you. [0] http://buildyourownlisp.com/
Judge Fang · 2020-04-22 14:25
What is the math behind CL macros? Are they a case of λ-calc combinators? Does anyone here have resources on the topic? Mathematical jn nature would be best. Thank you.
hash table · 2020-04-22 16:26
>>17875 This is interesting as I'm building a Lisp (surprise surprise, who isn't these days?). Looks like the book is pretty cheeky, pic related.
Agent Jones · 2020-04-22 23:56
>>17992 yeah it's obnoxious but the code examples make up for it
Joey · 2020-04-23 08:04
>>17875 Would've been nicer if everything outside of the standard library was covered in the book instead of just handwaving away the parsing aspect by forcing the reader to use a 4k LOC library.
XERXES · 2020-04-23 14:23
>>18005 Thank god I didnt have to focus on writing a parser back then.. I got to focus on the actual topic and started my research into parsing a whole lot later.
Cat Mother · 2020-04-23 19:00
>>18012 >>18005 I dunno, I wrote my lisp parser by hand. I learned a lot from the experience, especially implementing syntax sugar. Handwaving it away seems counter-productive.
John Titor · 2020-04-24 23:56
Been working on a Richii mahjong implementation for Emacs. So far just have hand generation and sorting, but it's been a fun dive into using Elisp for more than just Emacs configuration. Of course it's a 4 player game, and I don't particularly plan on writing netcode, so I'm looking forward to getting to try out some simple AI concepts in Elisp. >>18005 >>18014 +1 for writing a Lisp parser, not only is writing one quite trivial and a good introduction to handwritten parsers in general, but using almost any parser library is just overkill for S-Expressions. You can write an S-Expression parser in a few hundred lines of C, and a few hundred more to round off number formats and a few reader macros. Couple with an expression printer (which is also easy to reason about because it's just the inverse), and you're set. But I also agree that some people will just want to understand the basics of a dynamic language, and would get put off at having to figure out writing an RDP. Imho the bigger problem is that all these simple Lisp tutorials never lead on to the more interesting layer of implementation, such as closures or compilation.
Lunch · 2020-04-30 19:44
can we talk about CLIPS in this thread? Is CLIPS lisp?
(princ tripcode) -| · 2020-05-09 08:14
So, I released this last month: http://verisimilitudes.net/2020-04-16 Unfortunately, it's far too slow for practical usage, although it's not completely unacceptable. I had another SHA library design I could've pursued instead which is static, and just may. I'm growing bored with merely implementing SHA, however, so I'm going to start pursuing other work soon. >>18022 That's neat. I'm not particularly familiar with the game, but it's fun to play the meta-game and program a machine to play acceptably, isn't it? When considering games, I like to mull over the elimination of side-channels which would give an advanced player extra information, but I suppose that also wouldn't apply to this game much, if at all. On that note, I was playing M-x blackbox lately, having recently stumbled upon it, and considered how to make the traversal of the beam through the grid constant-time, as leaving it variable could result in revealing the complexity of the path, and struggled with this problem until realizing the best solution is to simply pregenerate all of this; then, although the generation time itself could be considered a side-channel as to the overall complexity of the puzzle, it's significantly less useful.
Nobody important · 2020-05-09 10:03
Why, when compiling lisp to C with ECL, does the binary produced invoke the interpreter and not just run the forms in the file. There must be a way to achieve what I desire.
Bob Arctor · 2020-05-09 12:33
Recently started using Emacs and want to configure some basic things. What's a good resource for Elisp 101?
swap · 2020-05-09 18:35
>>18371 You don't need elisp to configure "basic things", you can use customize for that. But if you want to learn elisp, I recommend learning the basics of common lisp, because the literature on CL is a lot better than Elisp, and they have a lot in common. Then you can either browse through the elisp manual or read random elisp source while looking up variables with C-h f and C-h v. That's how I got into Elisp, maybe not the best but it worked well.
Ivan Petrov · 2020-05-09 19:13
>>18371 Check the info within emacs. Type "C-h i" and it will bring you into the root info directory Then, search for elisp in there.
Colmerauer · 2020-05-11 18:23
I've recently finished my first game. It's written in Common Lisp and the code is like kicking dead whales down the beach ass. :3 https://decent-userna.me/php/dmomd.php
Kay · 2020-05-17 07:28
>>18369 Because you need the entire environment to run that Lisp, specifically. Macros, Garbage Collector, etc.
Cypher · 2020-05-18 14:40
>>18442 As someone who's new to Lisp, reading your code is a very nice resource for learning, Thanks for sharing it Lain, I still haven't tried out the game. Nice memes btw.
Donna Hawthorne · 2020-05-20 00:46
>>18442 Wow, this looks great! Guess it's time to learn trivial-gamekit.
Wintermute · 2020-05-26 14:31
Does anyone know a beginner good book for learning Guile? I'd like to contribute to Guix, but I don't have much programming experience at all. (as in, barely beyond hello world in python even, there is not any other language I already know well)
Shogun · 2020-05-26 21:46
>>18821 This is linked from the Guile reference manual. It teaches plain Scheme rather than Guile, but is extremely relevant. http://ds26gte.github.io/tyscheme/
Lunch · 2020-05-26 22:44
>>18825 Thank you. I'll take a look.
car · 2020-05-27 00:00
>>18825 is there any way to get this same content in epub or something? I don't really want to read it in a browser, and also it's blindingly bright with no obvious way to change to something dark.
Ivan Petrov · 2020-05-27 04:58
>>18828 https://doc.lagout.org/programmation/Lisp/Scheme/Teach%20Yourself%20Scheme%20in%20Fixnum%20Days%20-%20%20Dorai%20Sitaram.pdf
Zuse · 2020-05-27 12:30
>>18828 Not the same bok but this one also a decent scheme resource, though quite long. In epub format as requested
Apoc · 2020-05-27 14:41
>>18832 >>18835 thanks
Gyula Kovacs · 2020-06-11 19:02
Is it possible to implement a language with manual memory management like C in Lisp? I want to try my hand at writing a compiler, and Lisp's syntax seems like it would lend itself very naturally to this sort of thing.
Tyrell Wellick · 2020-06-11 22:34
>>19162 C-like language with Sexp-Syntax is of course possible. Probably even easer if you choose to do so in Lisp itself, since parsing would be "built in"-"out of the box". Though you probably wouldn't end up with anything like Lisp in a meaningful sense of the idea.
Hagbard Celine · 2020-07-01 17:37
Here's some Common Lisp I came across: https://nitter.net/Ngnghm/status/1235582644957700096 (labels(({(] &rest [)(apply([ ])[))([(])(elt(]())]))(](<)( do-external-symbols(]`:cl)(push`,]`,<))(sort <`string<`:key`string))(}(} {)({`688({`875({`398()"~{~A ~}~%"(]()))}(+`,{(*)})))({`381)({`816`2/9))) ({`561()#'}`(874,948 7,6009 4862,370 10,12249)`(3,2 4,4 2,1 1,0))) This is clearly very ugly, very obfuscated, and very dependent on some relatively minor details of the language. I've simplified it some as follows: (labels (({ (] &rest [) (apply ([ ]) [)) ([ (]) (elt (] ()) ])) (] (<) (do-external-symbols (]`:cl) (push`,]`,<)) (sort <`string<`:key`string)) (} (} {) ({ `688 ({`875 ({`398 () "~{~A ~}~%" (] ())) } (+ `,{ (*) }))) ({ `381) ({ `816 `2/9))) ({ `561 () #'} `(874 ,948 7 ,6009 4862 ,370 10 ,12249) `(3 ,2 4 ,4 2 ,1 1 ,0))) (labels (({ (position &rest rest) (apply (cl position) rest)) (cl-symbol (position) (elt (cl-symbols ()) position)) (cl-symbols (sequence) (do-external-symbols (symbol :cl) (push symbol sequence)) (sort sequence 'string< :key 'string)) (cl-call (} {) (princ (subseq ({ 398 () "~{~A ~}~%" (cl ())) } (+ { 1 }))) ({ 381) ({ 816 2/9))) ({ 561 () #'} '(874 948 7 6009 4862 370 10 12249) '(3 2 4 4 2 1 1 0))) I got bored simplifying it further. Take a peak at what it does and maybe finish simplifying it for me.
roll · 2020-07-01 21:26
>>19448 This lisp clearly got cancer.
Stallman · 2020-07-05 22:42
Just started "Systematic Program Design" which is based on the HtDP2e book and I'm having a lot of fun with it. To anyone that has completed the course, Do the design recipes teach domain-driven design (Eric Evans) or is it something completely different? The same thing with the testing in the course seems to be the test-driven design methodology but they never mention the name. Any recommendations on what to read after the course, I find the whole "designing and planning programs" thing pretty interesting. Maybe the "Programming and Programming Languages" course? Even if it has a lot of overlapping info.
(princ tripcode) -| · 2020-07-09 21:51
By working daily, I was able to get my Meta-Machine Code targeted at CHIP-8 in a presentable state for the third anniversary of the announcement: http://verisimilitudes.net/2020-07-07 This isn't the machine code thread, and I don't want to write a particularly long post with this, but it's pleasant to reach the culmination of work spanning years and three libraries written for it. I still need to add some important features, but will do so lackadaisically now. My familiarity with Ada lead me to use pseudo-enumeration types more, but I believe I was probably going to do that anyway; it's structured well enough, and I'll refine it and add the remaining documentation strings later, as well. I've noticed I tend to write very specific macros, over more general control structures, with these being good examples; I wrote macros for defining the commands, making it necessary to provide very little information, and the symbols use my own format for discussing the commands to drive the macroexpansion: (defzero 0XXX "Jump to COSMAC VIP NNNN") (defone 3XYY "Skip next if VX = NNN") (defone EX9E "Skip next if VX = key") The macros themselves are terrible, though. I want an assertion system like Ada, so I'd like to tell myself I may at some point write a set of macros for defining preconditions and postconditions. Similarly, I've given a decent amount of thought to how to efficiently implement an undo and redo mechanism, although it's by-nature opt-in, and I'd like to think that may happen at some point. I'm certain I'm going to free myself to work on other programs, now. I'll actually use my MMC more than I've been, and there are smaller Common Lisp libraries I'd like to write or finish. I've not even really started on implementing CL:FORMAT nor CL:LOOP; I want to at least start with implementing languages this year. Writing a pure library, lacking any need to venture outside of its host language, is so pleasant in comparison to writing other programs. Modern systems are almost explicitly hostile to actually writing standalone programs. There's always so much to do, in any case. >>18442 I've been intending to send an email, but such things slip away from me at times. This is a nice website, and I'm glad to be made aware of the work. We could link our websites, if wanting, but send me an email if interested in discussing anything that would benefit from being private. I don't see an email on the website, unlike mine. >>19162 The Lisp Machines had compilers for C, Ada, et al.; the technique is to compile those languages to Lisp, perhaps with declarations that enable the Lisp compiler to avoid allocations and whatnot.
Emmanuel · 2020-07-10 01:25
>>19511 >I'd like to tell myself I may at some point write a set of macros for defining preconditions and postconditions. I implemented this once while having an argument over whether preconditions and postconditions could easily be statically enforced in Common Lisp. I ended up defining a special defun and a special progn that statically ensured pre and post constraints were met. It wasn't pretty, but it worked.
Lady 3Jane.. · 2020-07-14 13:18
>>19511 >I've not even really started on implementing CL:FORMAT nor CL:LOOP; I want to at least start with implementing languages this year. You may be interested in the work Olin Shivers did with his loop macro for Scheme if you're not already aware of it. He goes to great lengths to have proper scoping rules for his loop macro, and while I would be surprised if you didn't have an alternative focus for your implementation, it's a good read none the less: http://www.ccis.neu.edu/home/shivers/papers/loop.pdf
Yet Another Lainon · 2020-07-15 12:42
Is using OOP in Scheme a sin?
Boris Grishenko · 2020-07-16 17:28
>>19578 I'm not sure there's such a thing as a sin in Scheme. The language is multi-paradigm and extensible, you're encouraged not only to use but even to implement any paradigm that makes sense for your program. But if you were to implement and use the boilerplatey, all-code-must-go-in-a-class, must-write-getters-and-setters-by-hand kind of OOP, that'd certainly count as penitence.
Dujour · 2020-07-16 20:16
>>19589 >I'm not sure there's such a thing as a sin in Scheme. I mean a situation that would make more experienced Schemers like: >NOOOO, your program must be FUNCTIONAL, NOOOO >The language is multi-paradigm and extensible, you're encouraged not only to use but even to implement any paradigm that makes sense for your program. I like the mixed paradigm the most, I want to use OOP for inheritance and spawning multiple instances of objects. >all-code-must-go-in-a-class, must-write-getters-and-setters-by-hand No, that would be disgusting.
Chani · 2020-07-19 00:28
>>19594 The SICP book had an entire section of making objects with message-passing based just about entirely on closures and `set!`.
Anonymous · 2020-07-19 00:58
>>19620 Fortunately my Scheme dialect supports OOP, no need to use bare closures.
Debbie Charteris · 2020-07-20 22:31
I keep reading that macros don't evaluate their arguments. How can a function like this work if nothing is evaluated? (defun red-or-blue (color) (cond ((equal color 'red) 'red) ((equal color 'blue) 'blue)))
Donna Hawthorne · 2020-07-20 23:35
>>19644 When a macro is called, its arguments aren't evaluated *automatically* (as opposed to what happens when a function is called). There's nothing to stop a macro from evaluating its arguments in its body, though.
Terzibashjian · 2020-07-21 03:33
>>19645 >its arguments aren't evaluated *automatically* Do you mean by eval? Is there a reason why evaluation is phrased as something the macro isn't doing, instead of something eval isn't doing? And without "automatically"?
Ivan Horvat · 2020-07-22 23:40
>>19644 >>19648 Macros don't have to evaluate all of their arguments before applying, which is partly what makes them special. Take the function 'if', which is a macro, and take look at this code block. (if (= 1 2) (format "impossible!" t) (format "duh, 1 cannot equal 2" t)) Now we are giving the function 'if' 3 arguments, the predicate (= 1 2), the consequence (format "impossible!" t) and the alternative (format "duh, 1 cannot equal 2" t). Obviously this if statement should return "duh, 1 cannot equal 2" because the predicate returned false, it wont evaluate (format "impossible!" t). However, this function only works properly because the function is a macro. If 'if' was a not a macro, but instead a regular function, it would have to evaluate ALL 3 arguments first before being allowed to apply them to the function. This "eval all and then apply" mentality is due to Lisp normally being an applicative-order language. So, if the function 'if' was a normal function and not a macro, running the function would return: "impossible!" "duh, 1 cannot equal 2" "duh, 1 cannot equal 2" You see this yourself if you try to make your own version of 'if' by using defun and cond. Long story short macros can chose what arguments to evaluate and what not to.
car · 2020-07-23 11:01
>>15857 Is it a good idea to start with GNU Guile? Especially since I'm thinking of running GNU GuixSD down the line and it uses Guile everywhere, but also because I want to break from C-based langs and not use Python.
Hagbard Celine · 2020-07-23 11:02
>>15857 Is it a good idea to start with GNU Guile? Especially since I'm thinking of running GNU GuixSD down the line and it uses Guile everywhere, but also because I want to break from C-based langs and not use Python. For the record, I currently know C, C++, Java, C#, Python, Shell Scripts and JS.
The Phantom Phreak · 2020-07-23 12:38
>>19676 >>19675 Yes, Guile is rapidly evolving and is currently the best language to work with GNU. Guile has convenient API for POSIX, has a Web server and supports most srfi "standards" and rnrs. Guile proved it is ready for serious applications, as it has Guix (a package manager and distribution) and GNU Shepherd (process supervisor, sysV init replacement) and many more. http://www.gnu.org/software/guile/manual/html_node/POSIX.html#POSIX http://www.gnu.org/software/guile/manual/html_node/Web.html#Web Guile's manual isn't the best for learning though, you should try "Teach Yourself Scheme in Fixnum Days" for basic stuff and then read the manual. https://ds26gte.github.io/tyscheme/ Other useful resources: https://schemers.org/ https://srfi.schemers.org/ They're all listed here, basically: http://www.gnu.org/software/guile/learn/ But you should probably learn Emacs and install emacs-paredit - it is the best editor for lisp generally. From my experience, editing Scheme code is painful manually, but paredit makes you forget about parens and you edit a higher structure, not only text.
Hopper · 2020-07-25 19:58
>>19679 >emacs-paredit Not him but thank you for mentioning this, I was searching for this tool because someone mentioned it on the IRC but forgot what it was called.
XERXES · 2020-08-03 14:56
Does anyone here use Lisp (well, preferably Common Lisp, but I'd love to hear about anything) for data science/machine learning/AI? I found some libraries for Racket and CL on the web but would like to hear about actual people's experiences. I'm currently learning Common Lisp and recently have taken a bit of an interest in data science. It seems that everyone I know uses Python for it, should I just cope and use Python/any mainstream language for that kind of stuff?
HELIOS · 2020-08-03 16:23
>>19870 >I would suggest something more conservative. Conserving what, Stallman's opinion that "voluntary pedophilia" doesn't hurt children or his dictatorship over GNU, even though he has no vision whatsoever about its future? It is just a programming language, more it is free software, it conserves free software and that's all that matters. If you're that religious about software and Stallman, at least make sure you drop all software of which maintainers signed the statement: https://guix.gnu.org/en/blog/2019/joint-statement-on-the-gnu-project/ Guix, Guile, GNU Social, Hurd, libc, binutils, gnupg, gettext, octave, emacs, gcc, gdb and more.
Kay · 2020-08-03 17:53
>>19675 >>19676 Guile is fine and has some great documentation on its implementation. However, like many Schemes, lots of core features are Guile specific, like the modules and the object system, so you're stuck with a reference implementation. Guile was planned to replace Emacs Lisp and become the de facto scripting language of all GNU projects, but this has had mixed success. They never took over Emacs. Guile is still used to script a variety of GNU projects, such as GIMP, so it's rewarding to learn it. The base technology is pretty awesome too. It's fun to read about the implementation. >>19870 >>19874 >>19875 Can't we discuss Guile without having meta-discussions about the developers and Stallman? Please?
over · 2020-08-03 19:05
>>19881 I find it *very* hard to believe that Guile is a one man project in any meaningful sense. Guile is almost 30 years old and has gone through multiple waves of developers. I'm sympathetic to your concerns, but I think they're irrelevant and emphasizing them here is a mistake. In contrast, the Common Lisp implementation CLISP broke functionality to make a political point about China. That would definitely be relevant in deciding whether or not to use CLISP. If possible, please sage for posts only pertaining to this topic.
Special Agent Bob · 2020-08-03 19:33
>>19880 >However, like many Schemes, lots of core features are Guile specific, like the modules and the object system, so you're stuck with a reference implementation. Is there even a single Scheme implementation that isn't in fact a new Lisp dialect? Guile does a good job with supporting rnrs and srfi, some srfis like srfi-9 records are even promoted over Guiles low level code.
↑ · 2020-08-04 03:41
>>15857 Are there any good IDEs for any lisp dialects that DO NOT require the use of Emacs? Between a history of RSI/carpal tunnel and general dislike of the user experience, I'd prefer to spend as little time as possible hitting control key combos.
Just another Random Lainon · 2020-08-04 05:12
>>19906 IIRC there's a common lisp plugin for atom and there's vlime for vim. I haven't tried either of those two so I can't vouch for them, I'm only aware of their existence.
Elliot Alderson · 2020-08-04 10:27
I'm trying to piece together toolkit which would allow me to talk to old Lego Mindstorms I'm playing around with using common lisp. I have the following implementation in python which is loosely based on this https://github.com/G33kDude/pyev3/blob/master/rcx.py Here's my code class Tower: def __init__(self, path): self.file = open(path, 'rb+', 0) self.dupe_bit_toggle = True def format(self, hex, pad=0): """Format hex command into full message.""" # header buffer = b'\x55\xff\x00' checksum = 0 for byte in hex: buffer = buffer + bytes([byte, 0xFF - byte]) checksum += byte checksum = checksum % 0x100 buffer = buffer + bytes([checksum, (0xFF - checksum)]) + bytes(pad) return buffer def send(self, hex, read=True, pad=0): """Send an RCX opcode sequence through the IR tower""" message = self.format(hex) self.write(message) if read: try: return self.read() except IOError: return None def write(self, value): """Write to the IR tower""" print(value) self.file.write(value) def read(self): """Read from the IR tower""" return self.file.read() How would go about implementing something like this in lisp? I have few pieces which I'm not sure how to piece together. (with-open-file (stream "./lisp_test.txt" :if-exists :append :if-does-not-exists :create :direction :io :element-type '(unsigned-byte 8)) (write-sequence (concatenate 'vector #(#x55 #xff #x00) #(#x21 #x47)))) (defun nqc-complement (x) (- #xFF x))
Neo · 2020-08-04 11:56
>>19906 There's something like paredit on emacs but for vim, don't recall its name.
Nobody important · 2020-08-04 12:29
>>19906 >Are there any good IDEs for any lisp dialects that DO NOT require the use of Emacs? Between a history of RSI/carpal tunnel and general dislike of the user experience, I'd prefer to spend as little time as possible hitting control key combos. Emacs is not usable out of the box, you need to adapt it for yourself.
⍕ · 2020-08-04 13:01
>>19906 You can try https://portacle.github.io/ or https://github.com/hlissner/doom-emacs if you're lazy that is
HELIOS · 2020-08-04 13:44
>>19916 (defvar *file*) (defun format (hex) ...) (setf *file* (open "test.txt"...) (write-sequence (format hex) *file*) (close *file*)
Tequila · 2020-08-08 05:36
>>15857 Hello all. I'm working on a company-backend for Ruby as a fun side project. I'm having a small issue with the syntax of elisp; what I want to do is create a function, rslc-find , that can take in a comparison function and subsequently use that in a seq-find expression. However, when I do this, I get errors saying the symbol is void. What am I doing wrong? (defun rslc-get-candidates-list (prefix) "Returns 'rslc-symbols' if the prefix is a substring of one of the strings in that list. If it's full string match, then it returns the result of rslc-get-ri-object-info" (interactive "sEnter prefix: ") (defun rslc-find (cmp-fn) (seq-find (lambda (rhs) (cmp-fn prefix rhs)) rslc-symbols)) (cond ((rslc-find 'string=) (rslc-get-ri-object-info prefix)) ((rsc-find 'string-prefix-p) rslc-symbols) (t nil)))
Mario Rossi · 2020-08-08 05:41
>>20096 Of course I figure out the issue right after I post. I needed a funcall : (defun rslc-find (cmp-fn) (seq-find (lambda (rhs) (funcall cmp-fn prefix rhs)) rslc-symbols)) That does bring me to another question, are there cases when I can't do this, and are there alternative ways of passing functions in?
Zero Cool · 2020-08-08 07:08
I'm currently making a solitaire game (sheer rip-off of Shenzhen I/O's solitaire) in Common Lisp with OpenGL - in part to dip back in the language, but mainly to learn OpenGL. Usually when writing C I'm taught how to prioritize data structures over fancy code. I feel it's a bit eerily similar how the macros I make whenever I want to make something declarative (defining programs, textures, renderers etc) feels like a synonym for writing an interpreter for a complex structure in my C programs.
let · 2020-08-08 12:35
>>20097 It might be easier to explain why funcall is necessary. Symbols in elisp have both a function slot and a data slot which can be bound independently. The code below is perfectly valid and produces the list (of lists): ((a b) (a b)). (let ((list '(a b))) (list list list)) When the reader finds a symbol at the head of a list it retrieves the symbol's function slot, whereas the data slot is used when the symbol is in an argument position. So list names both a function and a variable in the code above. Now, when you call a function, the arguments are bound to the data slot of the function's named variables, so trying to call cmp-fn as a function will fail since there's nothing in its function slot. Funcall pulls the value out of a symbol's data slot and calls it as a function. This is all in contrast to Scheme which uses a single, unified, binding for all symbols. In Scheme there's no funcall to worry about, but you can't call a variable list without shadowing the list function.
Church · 2020-08-11 22:38
I'm making a file manager and I would like to store all nodes in a directory somewhere. Should I use lists or vectors if I care about performance? https://www.gnu.org/software/guile/manual/html_node/Vectors.html#Vectors >The advantage of vectors over lists is that the time required to access one element of a vector given its position (synonymous with index), a zero-origin number, is constant, whereas lists have an access time linear to the position of the accessed element in the list. but >Unlike lists, the length of a vector, once the vector is created, cannot be changed. Guile also provides vlists https://www.gnu.org/software/guile/manual/html_node/VLists.html#VLists >VLists are immutable lists, which can contain any Scheme object. So basically an immutable list, but with access speed like in a vector. My file manager will refresh directory contents every n seconds and the list/vector will be rewritten every refresh, no modifications. I'm probably just scared of vectors, since I didn't yet read much about them. What should I use?
Erik Johansson · 2020-08-12 00:53
>>20190 Eventually I picked vectors due to their simplicity and performance.
Splicer · 2020-08-12 19:13
>>20190 I don't have the expertise to provide direct guidance, but I am going to think aloud about your problem, mostly as an exercise for myself. As your quotes summarise, access time and fixed length are each option's most obvious drawbacks. Access time for lists is far from a big deal for the average directory listing's size, but if you wish your file manager to escalate to arbitrarily long listings then access time, while not your biggest problem, will be one of your problems, and thus you shouldn't use lists. As for vectors, their fixed length forces you to make a new one for every new directory or refresh, which may or may not be acceptable. All of this assumes a naïve implementation - one could surely provide implementations for specific problematic cases. Important factors to consider are what form your data comes under, and what you want to do with it afterwards. A directory listing is an unsorted collection, which file managers often present to the user sorted in one of several possible ways. Will yours do this? How many different sorts will you support, and how often do you expect to change between them? Contrast this with other features, like adding or removing files to/from the listing (after a refresh or a user action) - do you expect that to happen a lot? Each data structure offers different time-memory trade-offs for each use case (you could even use some sort of binary tree where new elements are inserted directly into their sorted position - but which you have to rebuild from scratch for each sort). Alternately, if your API will sort directory listings for you, your priority should probably be to make the least transformations to the data it returns. >My file manager will refresh directory contents every n seconds Excuse me for prying, but is that a deliberate design choice or only the best you've figured so far? There are other ways, in case you don't know. The kernel Linux provides inotify (man 7 inotify), by which your program can be notified of filesystem events. That sounds great, but it comes with its own trade-offs; harder portability would be one, inconsistent user experience could be another (if you rely on inotify and don't provide a fall-back mechanism, your file manager will require manual refreshing when browsing non-inotify-enabled filesystems, like network mounts). Take all of this with a grain of salt, as I have only the shallowest familiarity with the topic.
Switch · 2020-08-12 20:33
>>20205 >Will yours do this? Yes, but it will be handled by universal grid object - the architecture is object-oriented and each element of the DE I'm making will do one thing and do it well. The purpose of the file manager is to do operations on files - basic displaying, copying, creating files and folders, moving, picking files for other programs etc. The universal grid will handle all basic types of sorting, displaying columns, rows, etc. - it is going to be multi purpose - displaying photos in photo gallery, displaying files in file manager, etc. >How many different sorts will you support Just as I mentioned - all basic sorting types - by date, name, asc, desc, but it'll be handled by the universal grid. The grid will also support hiding some types of objects - for example it will be able to show only jpegs or folders. >and how often do you expect to change between them? The file manager only displays files as they are, but the refresh rate has to be fast enough to detect change and notify the user, for example if other process removes a file from a directory. >Contrast this with other features, like adding or removing files to/from the listing (after a refresh or a user action) - do you expect that to happen a lot? To be honest I decided the list (vector actually) will be read only and operations on files will be transactional - this way I can ensure correctness. >Alternately, if your API will sort directory listings for you, your priority should probably be to make the least transformations to the data it returns. I'm not sure what is better - to have quick access to vector elements or to leave list almost unchanged as the scandir procedure gives me. scheme (define-method (refresh-nodes (fm <file-manager>)) (spawn-fiber (lambda () (define files (scandir (get-work-directory fm))) (set-displayed-nodes fm (list->vector (map (lambda (file) (make-file file (stat file) (canonicalize-path file))) files)))))) >Excuse me for prying, but is that a deliberate design choice or only the best you've figured so far? The later. This project is for me to learn Scheme (Guile) and eventually to create object-oriented, extensible DE/GUI toolkit. I hate making programs that don't solve real problems, so I decided to make something useful. >The kernel Linux provides inotify (man 7 inotify), by which your program can be notified of filesystem events. Nice! I was expecting something like this exists, but never heard of it. I'll check the POSIX interface (or other part of the manual) for it. >That sounds great, but it comes with its own trade-offs; harder portability would be one I want my DE to run on GNU/Hurd and at least in text mode on Windows one day. >inconsistent user experience could be another (if you rely on inotify and don't provide a fall-back mechanism, your file manager will require manual refreshing when browsing non-inotify-enabled filesystems, like network mounts) My project is all about consistency, I want to provide the same experience for the whole system. I can always detect if inotify is available on the system and switch refresh methods depending on this.
DEBUG-CONTENTS · 2020-08-13 08:35
>>20096 Also keep in mind that (e)lisp has no local defuns. Each defun in global, even if you write within another defun. Another general point is that the company guys recommend writing a completion-at-point backend, instead of a custom company one (unless the completion takes too long to compute).
Spike Spiegel · 2020-08-13 19:33
>>20206 So you're writing a modular, portable DE in Guile. Well, if it ever reaches a working state the Guix people should love to hear about it (and they wouldn't be the only ones - please do blog occasionally if you make progress). >I'm not sure what is better - to have quick access to vector elements or to leave list almost unchanged as the scandir procedure gives me. This may well be a case of premature optimisation, since I expect that a listing long enough for list access time to matter would give you other performance problems anyway. At any rate you should conduct benchmarks to base your decisions on real data rather than conjecture. I'd choose a data structure that's easy to work with for the task, and worry about performance later. It sounds like the universal grid will be doing a lot of sorting and filtering. You need to walk the whole collection for those, so fast random access doesn't help much - lists are a more natural first choice. However, it must also let the user pick some arbitrary elements, and send the picks back to the calling program - things get interesting here. I don't expect that the universal grid will be passed file handles, or other arbitrary objects - it only needs to know about objects that have a series of fields which they can be sorted or filtered on. Yet when the user picks some of those 'sortable objects', the file manager must be able to map them back into the file objects they stand for. So, how about neither? This sounds like a case for a hash table to me. I see it like this: - the file manager obtains a directory listing - from it it builds a collection of file objects, as you show - it saves them as a hash table which maps base file names to file objects, since conveniently file names must be unique within a directory (make sure your structure's hashing is case-sensitive, as are many filesystems you'll work with) - it then maps this collection into a series of 'sortable objects' and passes it to the grid - the grid returns a series of strings corresponding to the primary keys of the selected objects - the file manager can readily look up those strings in its hash table to find the corresponding file objects This approach makes sense provided that the grid will always work on objects that have some unique 'primary key' property, such that the calling program can find the original objects based solely on that key. Another way would be to pass a vector of 'sortable objects' and get back a series of indices into that same vector - the grid would then need to remember what each object's original index was, so it can return the correct one regardless of current sorting. Also, suppose what happens when the user changes the sorting while some files are selected; if you want the grid to keep the same objects selected in their new locations, then the grid will probably need 'sortable objects' to have a unique key that it can find them based on.
Wintermute · 2020-08-13 22:12
>>20226 >Well, if it ever reaches a working state the Guix people should love to hear about it (and they wouldn't be the only ones - please do blog occasionally if you make progress). I will make an announcement once I finish a proof of concept. I was collecting ideas for its implementation for over a year and now I'm experimenting with the proper way of implementing those ideas. I have to make sure I'm a good enough developer before I publish the code, to prevent someone more experienced from derailing my object-oriented architecture to some monolithic garbage. That's why I'm improving my Scheme skills by actually writing something. >wall of text My brain is too small to respond to all this today, but you gave me an idea - DE objects - a.k.a. blocks (file manager, WM, search , etc.) can send readers together with objects to the grid, that is a reader would be a procedure applied on an object to obtain data used for sorting. The grid would just run the reader on data to obtain keys for sorting. Is my idea just fuarrrked up, or is the real OOP like this? I have to predict all things at once to write working code, but after writing the initial framework, creating GUI applications will be simpler than ever.
Knuth · 2020-08-18 14:55
>>20226 Okay, I have some progress on adding nodes and made an algorithm for the purpose, don't know if there's a better way to implement it, but whatever. I decided to use srfi-43 implementing a vector library, which makes some operations on vectors easier. Here's my current implementation. Could it be I fuarrrked up the tail calls and made the recursion hog resources? What I do here is I make one array to contain both already selected nodes and nodes to select, then I copy each node once - I ignore copies of the same node. (define-method (select-nodes (fm <file-manager>) (nodes <vector>)) (define all-nodes (vector-append nodes (get-selected-nodes fm))) (define unique-nodes (vector-copy all-nodes 0 1)) (let loop1 ((i 0) (j 0)) (if (< i (vector-length all-nodes)) (if (< j (vector-length unique-nodes)) (if (eq? (file-path (vector-ref all-nodes i)) (file-path (vector-ref unique-nodes j))) (loop1 (+ i 1) 0) (loop1 i (+ j 1))) (begin (set! unique-nodes (vector-append unique-nodes (vector (vector-ref all-nodes i)))) (loop1 (+ i 1) 0))))) (set-selected-nodes fm unique-nodes)) The problem is something in my program really lags - I have to do some benchmarks to check what's wrong. Does anyone knows the best way to measure time in Scheme to check how long something took?
setq · 2020-08-18 15:01
Im new on LISP im trying to learn from the text book Lisp, Lore and Logic and Algebraic View of LISP. It its ok to the let the parenthesis in a separated line as I did? (defun power (base expo) (cond ((eq expo 0) 1) ((eq expo 1) base) (t (* base (power base (1- expo)))) )) (defun fibonacci (n) (if (<= n 1) 1 (+ (fibonacci (- n 2)) (fibonacci (1- n))) ))
Marly Krushkhova · 2020-08-18 15:05
>>20330 It is okay to do this, when you have long lists of something, but it's a bad habit from languages with C-like syntax. I encourage you to learn Emacs with paredit, this will make you completely forget about the parens. https://www.gnu.org/software/emacs/ https://www.emacswiki.org/emacs/ParEdit Documentation: https://mumble.net/~campbell/emacs/paredit.html It took me like 3 days to master paredit and now I can't code without it.
↑ · 2020-08-18 15:14
>>20331 Haha its funny how you got Im comming from C background (you are right), I never used emacs for real I just tried long time ago but dont managed to learn it for real. You use it with GTK or in pure text mode? You said you mastered the usage of the paredit in 3 days, but how about the emacs, how many time is needed to got comfortable?
Neo · 2020-08-18 15:43
>>20332 >You use it with GTK or in pure text mode? Normally GTK, but when X dies, I use the text mode. >but how about the emacs, how many time is needed to got comfortable? About week to get comfortable with it, if I remember correctly. If you know vim already, you can use evil mode to emulate vim with Emacs. You should probably ask lainons in the elisp thread for more questions about Emacs, I'm not an advanced user >>>/λ/7270
Nameless · 2020-08-18 21:07
I've been looking to improve my programming environments lately, and I know my Common Lisp setup is subpar, but SLIME and paredit go a good ways from what it otherwise would be on their own. I mostly use C-c C-d C-d, slime-describe-symbol, and this goes a long way on its own, with debugging made the most important optimization; I can't get M-., slime-edit-definition, to work, and the source form is often littered with garbage macroexpansions past standard Common Lisp, but it's usually good enough to see what I wanted to see anyway. Two important bindings to keep in mind are M-TAB, completion-at-point, and C-c C-s, slime-complete-form, which really save me some typing now that I'm aware of them. I've recently learned of C-c C-m, slime-expand-1, which makes viewing macroexpansions much more convenient than it was at the REPL. I try to use M-?, paredit-convolute-sexp, but it doesn't usually do quite what I need, so I just undo it immediately afterwards. If anyone has other helpful commands, I'd be interested in seeing them. It's awful that I've been programming with Common Lisp for years, but only recently took the time to learn of some of these commands, and my M-. still doesn't work. It goes to show how easily humans can do the work of the machine without realizing how awful it is, just because some of it's correctly automated away. I want to try to hack more mindfully from now on, and properly see when I'm doing something the machine should, so I can automate it instead. I'll never be close to the ideal with the software available to me now, but trying for anything less is wrong. >>20100 That's neat, although using OpenGL from Common Lisp seems like it would be painful. >Usually when writing C I'm taught how to prioritize data structures over fancy code. That's probably because writing fancy C code is an exercise in vulnerabilities. >I feel it's a bit eerily similar how the macros I make whenever I want to make something declarative (defining programs, textures, renderers etc) feels like a synonym for writing an interpreter for a complex structure in my C programs. These may very well be isomorphous, although this discussion is a bit too vague to use such terms concretely. In any case, this is part of the power of Lisp, being able to build in these interpreters or whatever directly into the language.
Batou · 2020-08-18 22:01
Apress is having a sale right now. So you can get Practical Common Lisp on hardcover for 12 bucks, plus other new Lisp books on the Condition System.
Trinity · 2020-08-18 22:31
I wasn't expecting scheme to handle this so easily. ;takes a predicate and some lists of equal length, the predicate should take an amount of arguments equal to the amount of lists ;returns the same amount of lists but each list has only the corresponding elements that satisfy the predicate ;(select even? '(1 2 3 4)) ;(2 4) ;(select > '(1 2 3 3) '(0 1 4 2)) ;(1 2 3) ;(0 1 2) (define (select . args) (define (cons-n n elem l) (let rec ((n n) (l l)) (cond ((= n 0) l) ((> n 0) (rec (- n 1) (cons elem l)))))) (let ((pred (car args)) (lists (cdr args))) (let ((top-lists-len (length lists))) (let rec ((lists lists)) (cond ((null? (car lists)) (apply values (cons-n top-lists-len '() '()))) ((pair? (car lists)) (let ((first-elems (map car lists))) (let ((is-pred (apply pred first-elems))) (call-with-values (lambda () (rec (map cdr lists))) (lambda lists (cond ((not is-pred) (apply values lists)) (is-pred (apply values (map cons first-elems lists)))))))))))))) On a similar note, if you had information that always went together, would it be better to have separate lists like the select greater than example or would it be better to group them in an alist mapping symbols to values or even a single list like this: (define select filter) (select (lambda (x) (> (list-ref x 0) (list-ref x 1))) '((1 0) (2 1) (3 4) (3 2))) ;((1 0) (2 1) (3 2)) (select (lambda (x) (> (cdr (assoc 'left x)) (cdr (assoc 'right x)))) '(((left . 1) (right . 0)) ((left . 2) (right . 1)) ((left . 3) (right . 4)) ((left . 3) (right . 2)))) ;( ; ((left . 1) (right . 0)) ; ((left . 2) (right . 1)) ; ((left . 3) (right . 2)) ;) Putting call-with-values everywhere might get annoying, but it'd also be convenient to be able to build up the lists independently.
Hong, Guil Dong · 2020-08-18 22:53
>>20349 Isn't this handled by one of SRFIs?
protected · 2020-08-18 23:02
>>20332 This varries from person to person. It's not hard, if you know what you're doing, but it's easy to get confused or form bad habits. Remember that there's no right way to use Emacs, the entire point is that you have an environment you control. Use arrow keys if you want, use the menu-bar if you want. The basics you must know are: 1. What are minor/major modes 2. How do you manage buffers 3. How do you manage windows 4. How do you invoke commands The next ones are optional, but can get you a long way: 5. How to use the help system 6. How to use Emacs Lisp Numbers 1-4 can be understood in less than an hour. But just like a good game, it's combinations offer immense possibilities.
Faye Valentine · 2020-08-18 23:23
>>20350 I haven't seen anything. Do you remember which srfi?
HELIOS · 2020-08-18 23:41
>>20352 srfi-1 I guess? I saw a similarly looking procedure in srfi-43 for vectors, so I assume there should be something for lists too. Just check the procedure index: https://srfi.schemers.org/srfi-1/srfi-1.html#ProcedureIndex fold might be the procedure. If there's nothing like this, then sorry. I didn't read your whole code, just the comments and it seemed similar to the vector procedures I studied yesterday.
Erik Johansson · 2020-08-18 23:47
>>20353 The filter function in srfi-1 only takes 1 list. It'd be nice if it did an arbitrary amount of lists though.
fsociety · 2020-08-18 23:49
>>20353 If you're the guy that was searching for unique nodes in two vectors, have you considered the possibility that that the result of vector-append isn't using the same memory as the first argument. If I'm remembering right, vectors are usually supposed to be allocated all at once instead of adding elements one at a time.
Netrunner · 2020-08-19 00:08
>>20354 Sad, procedures from the vector library seem to always take one or more vectors. >>20355 >If you're the guy that was searching for unique nodes in two vectors Yes, that's me. >have you considered the possibility that that the result of vector-append isn't using the same memory as the first argument I don't want to use the same memory, setting "selected-nodes" takes place at the end of the method. >If I'm remembering right, vectors are usually supposed to be allocated all at once instead of adding elements one at a time. vector-append from srfi-43 doesn't really modify the vector - it takes two vectors and returns a new from them one. I put the result of appending to unique-nodes. I also probably know why my program behaves strangely - each fiber (from Guile Fibers library, a thread like something) modifies or tries to access the slots of an object. That's why I have to either redesign my message API or make a metaclass modified in a way that makes getters and setters work on messages that are thread safe (if that's the correct way of saying what actually happens).
Otto Normalverbraucher · 2020-08-19 00:09
>>20356 >returns a new from them one. *returns a new one made from them
McCarthy · 2020-08-19 00:44
The book im following asked to implement recursive functions to compute if a number is a prime (return the number itself if not return NIL) and compute the least element in a list. I dont know how to use variables yet, thus I used to functions to make my implementation, its a bad thing to use a wrapper to a internal recursive function in this way? The code: (defun min-intern (l n) (cond ((atom l) n) (t (if (< (car l) n) (min-intern (cdr l) (car l)) (min-intern (cdr l) n))))) (defun my-min (l) (min-intern (cdr l) (car l))) (defun prime-intern (n d) (cond ((equal d 1) n) (t (if (integerp (/ n d)) nil (prime-intern n (1- d)) )))) (defun my-prime (n) (if (< n 2) nil (prime-intern n (1- n))))
Marly Krushkhova · 2020-08-19 09:50
>>20360 FYI, in Lisp you can define "local" functions using flet or labels, and variables using let or let*. In min-intern, you probably want your base-case to be (null l), not (atom l), even though nil is also an atom. There's no reason do to "(cond (a b) (t c))", especially if c is an if expression. This would have been prettier: (defun min-intern (l n) (cond ((null l) n) ((< (car l) n) (min-intern (cdr l) (car l))) ((min-intern (cdr l) n)))) (though replacing the names "l" and "n" with "list" and "smallest" would make it more readable). And to show how local variables work, with a non-tail recursive implementation, consider this: (defun my-min (n) (if (null (cdr n)) (car n) (let ((min (my-min (cdr n)))) (if (< (car n) min) (car n) min)))) Regarding prime-intern, you don't need equal to compare numbers. = is used for that (so in your case "(= d 1)"). You don't need an if to negate an argument, just use (not ...) as the condition for cond. A cond expression may fall-through, in which case it will return nil. To check if a number can divide another, it is more usual to use (rem n d) and check if it's equal to 0 (or not in your case). When calculating the prime factors, you don't have to iterate one by one, but that's not a lisp issue. In my-prime, it would have been nicer to do something like (defun my-prime (n) (and (>= n 2) (prime-intern n (floor n 2)))) instead of an empty if case (I also skipped all the impossible divisors). I hope my comments could help.
Knuth · 2020-08-19 09:52
>>20368 Tabs messed the code up. Just copy it into Emacs and press C-M-h C-M-\ .
Judge Fang · 2020-08-20 01:29
>>20368 Im having hardtimes to understand your first example, keep in my I still very noob in LISP, just regarding the COND, if I got how COND works it is a list of (test action) where if all test fails the COND return NIL. But in your example the last expression is a call to min-intern but dont have an action, can you explain me why it works?
HELIOS · 2020-08-20 12:31
>>20377 Yes, cond is a list of clauses, that are tested until one returns non-nil. Each clause is a list that starts with a condition, that is evaluated. If the condition is non-nil, the entire clause is treated as a progn. That also means that if a clause only consists of a condition, that the result of that condition will be returned. Try evaluating (cond) , (cond (1 2)) , (cond (nil 1) (2)) , and other variations. You'll learn the most by playing around with these simple examples (and reading the specification, I guess).
car · 2020-08-25 00:06
I want to split a string into a list of its substrings. What's the best way to go about this?
Nemissa · 2020-08-27 03:06
Everybody who knows what they are doing in the Common Lisp world imports this same regular expression library... I however don't know wjat I'm doing! :p [code:lisp] (defun split (str ch) (let ((end (length str)) (pos nil) (idx nil) (result nil)) (loop while end do (setf pos (position ch str :from-end t :end end)) (setf idx (if pos pos 0)) (push (subseq str idx end) result) (setf end pos)) result)) [/code]
Neuromancer · 2020-08-27 12:41
>>20452 I wrote this function a while ago: (defun split-at (seq &rest at) (if (null at) seq (let* ((p (position (car at) seq))) (cons (apply #'split-at (if p (subseq seq 0 p) seq) (cdr at)) (and p (apply #'split-at (subseq seq (1+ p)) at)))))) Because of the &rest at , you can use it to split a sequence as deep as you want. Parsing a CVS file could stupidly be done by calling (split-at *cvs-data* #\newline #\,) >>20489 Consider looking into the do macro. It's a bit harder to understand that loop, but it should fit your use-case well.
word · 2020-08-27 12:42
>>20495 The reference to >>20489 somehow broke?
if · 2020-08-27 15:34
>>20495 Thanks. That makes life way easier for me
Sipho Nkosi · 2020-08-27 19:30
Why the use of QUOTE or ' twice make it returns a list when applied to a symbol? [1]> (listp 'foo) NIL [2]> (listp ''foo) T
Joe Bloggs · 2020-08-27 20:38
>>20500 Adding a 'x is the same as writing (quote . x) , so ''x is the same as (quote . (quote . x)) . Evaluating that, you get 'x , that's the same as (quote . x) , which is a cons-cell, and according to (listp object) == (typep object 'list) == (typep object '(or cons null)) is a list.
Nell · 2020-08-27 21:58
>>20501 But 'x is not the same as the dotted list (quote . x) at leat for clisp implementation > (equal 'x (cons 'quote 'x)) NIL In fact it is equal to direct application of QUOTE to x, but I think i got what is happening since the evaluation of my example in the other post will be (quote foo) It makes sense that it is a list.
Anonymous · 2020-08-27 23:24
>>20502 My bad, 'x is (list 'quote 'x) . And, you should be comparing (list 'quote 'x) to ''x , because 'x evaluates to x , while ''x actually evaluates to 'x (think about it this way: quote is the inverse operation of eval ).
bit · 2020-08-29 04:22
>>20341 got my hardcover copy today! it's genuinely a really nice book.
Cowboy · 2020-08-30 22:43
That my attempt on create a function to exchange first and last element in a list. It seems very odd.. How you would implement this function? (defun swap-first-last (lst) (let ((first-elem (car lst)) (last-elem (nth (1- (length lst)) lst))) (cons last-elem (cdr (reverse (cons first-elem (cdr (reverse lst))))))))
Nguoi La · 2020-08-31 07:01
>>20551
Zuse · 2020-08-31 08:21
>>20551 Similar to >>20559, but slightly different: (defun swap-first-last (list) (append (last list) (cdr (butlast list)) (list (car list)))) A lot of Lisp tricks boil down to knowing the little details of given functions.
Agent Jones · 2020-08-31 22:06
Does anyone have any suggestions for learning Common Lisp in a relatively time constrained environment for someone who has already read several books with examples in Scheme (and a couple versions of the standard), and enough Elisp to maintain a moderately large GNU Emacs configuration (but very few projects)?
if · 2020-09-01 01:03
>>20567 http://www.gigamonkeys.com/book/ Work through this.
Masami Eiri · 2020-09-01 02:25
>>20569 I had this book downloaded on my machine, but I wasn't certain it was the right book for my current situation. With your suggestion it will likely be what I work throughthough, as I don't see anything that would disuade me.
Gyula Kovacs · 2020-09-01 02:29
I forgot to back and say thanks, I really enjoyed both codes, and i did not knew about 'butlast' thats the major cause of my Odd code >>20559 What is the editor you are using in this picture? >>20560 You changed the implementation from the other guy to uses less "cons" and have less performance impact? I have seem something about this in the book Gentle Introduction to Symbolic Computation.
Boris Grishenko · 2020-09-01 08:17
>>20575 > What is the editor you are using in this picture? Looks like terminal Emacs. > You changed the implementation from the other guy to uses less "cons" and have less performance impact? It should cons just as much, as (list x) is the same as (cons x nil) . The only difference in performance I could recognize is that I didn't use the generic sequence operator concatenate but the list-specific append instead.
DEBUG-CONTENTS · 2020-09-01 13:13
Should I learn Common Lisp or Scheme?
Elliot Alderson · 2020-09-01 15:21
>>20581 Probably try both and see what makes the most sense to you. People that like either will recommend you just that, the one they happen to like, not the one that will fit you best.
Hacker · 2020-09-01 17:59
>>20581 Echoing the above, no reason not to learn both. People will probably disagree with me but I think Scheme has a place in circumstances like SICP et al, its simplicity lends itself to well to getting a good grounding of CS topics. CL is bigger and I'd go for that when you're looking to build something.
push · 2020-09-01 22:39
Can someone please give me an explanation why the last call dont works? Even using #'my-function or (function myfunction), the symbol 'my-function' is not supposed to be evaluated to the lambda expression and then used as a function like when using apply or funcall? [15]> (setf my-function #'(lambda (x) (* 10 x))) #<FUNCTION :LAMBDA (X) (* 10 X)> [16]> (funcall my-function 15) 150 [17]> ((lambda (x) (* 10 x)) 15) 150 [18]> (my-function 15) *** - EVAL: undefined function MY-FUNCTION The following restarts are available: USE-VALUE :R1 Input a value to be used instead of (FDEFINITION 'MY-FUNCTION). RETRY :R2 Retry STORE-VALUE :R3 Input a new value for (FDEFINITION 'MY-FUNCTION). ABORT :R4 Abort main loop
roll · 2020-09-02 08:03
>>20593 Symbols have a value and a function slot, which is why it's called a "LISP-2". In the first line, you set the value slot to a function (lambda ...). Lisp is all about evaluation, a lot of things are self-evaluating (eg. numbers), symbols evaluate to the value in their value slot and lists are evaluated as function calls. This is done by taking the car of the list, and checking it's function slot, and then deciding what to do depending on that. Since my-function seems to have no function value, the error is thrown, as Lisp can't decide what to do. If you had set the function slot like this (setf (symbol-function 'my-function) #'(lambda (x) (* 10 x))) then it would have worked, as Lisp recognizes this as a regular function, evaluated all arguments and then calls the lambda expression.
Cowboy · 2020-09-03 01:18
>>20615 Thanks for the explanation its make lots of things make sense, I just noticed when doing applicative programming the 'funcall' accepts a symbol bounded in the value cell instead of function cell like. [9]> (setf (symbol-function 'my-func) (lambda (x) (* x x))) #<FUNCTION :LAMBDA (X) (* X X)> [10]> (funcall #'my-func 7) 49 [11]> (funcall my-func 7) *** - SYSTEM::READ-EVAL-PRINT: variable MY-FUNC has no value The following restarts are available: USE-VALUE :R1 Input a value to be used instead of MY-FUNC. STORE-VALUE :R2 Input a new value for MY-FUNC. ABORT :R3 Abort main loop Break 1 [12]> [13]> (setf my-func2 (lambda (x) (* x x))) #<FUNCTION :LAMBDA (X) (* X X)> [14]> (funcall my-func2 7) 49 [15]> (funcall #'my-func2 7) *** - FUNCTION: undefined function MY-FUNC2 The following restarts are available: USE-VALUE :R1 Input a value to be used instead of (FDEFINITION 'MY-FUNC2). RETRY :R2 Retry STORE-VALUE :R3 Input a new value for (FDEFINITION 'MY-FUNC2). ABORT :R4 Abort main loop
x&lt;-&gt;y · 2020-09-03 10:05
>>20635 Well, funcall is just a function. As mentioned in >>20615, eval checks the first element's function slot, and for all others the value slot.
Lain Iwakura · 2020-09-08 14:45
I made a procedure for finding unique elements of a vector and putting them into a new vector. I will then use it to correctly select files in my file manager, then I will get back to the list of needed features for the file manager. I tried implementing the algorithm on just one loop, but something didn't work. This is my current implementation, if you have a better idea, tell me please. It uses srfi-43 for some vector procedures. scheme (define (vector-unique v) (define unique #()) (define element '()) (let loop-v ((i 0)) (if (< i (vector-length v)) (begin (set! element (vector-ref v i)) (let loop-u ((j 0)) (if (< j (vector-length unique)) (if (eq? element (vector-ref unique j)) (loop-v (+ i 1)) (loop-u (+ j 1))) (begin (set! unique (vector-append unique (vector element))) (loop-v (+ i 1)))))))) unique)
Incognito · 2020-09-08 15:41
>>20724 Honestly, it would be easier to construct a list and then convert it into a vector when finished. Also, it would be better to use let-local variables instead of modifying constants (unique and element). I would have done something like (define (unique lst) (if (null? lst) lst (cons (car lst) (unique (remove (lambda (e) (eq? (car lst) e)) (cdr lst)))))) (define (unique-vector vec) (list->vector (unique (vector->list vec)))) but if you don't want to convert the vector into a list and back, maybe (define (unique-vector vec) (let loop ((i 0) (unique '())) (cond ((>= i (vector-length vec)) (list->vector unique)) ((member (vector-ref vec i) unique) (loop (+ i 1) unique)) (else (loop (+ i 1) (cons (vector-ref vec i) unique)))))) would be more to your liking. Optionally, add a reverse before applying list->vector to preserve the original order in the list.
Anonymous · 2020-09-08 16:13
>>20726 I'll take a closer look at your code, once my brain stops being a potato, but thanks for suggestions. I picked operations on vectors over lists, because they have performance advantage, which is important, since the feature will be used in my file manager. I'm not sure if I want to do converting at all - the list/vector of selected files will probably be quite big and unneeded conversions can affect the performance. Anyway, the feature works now (yay!), which is a success after debugging my program in its different parts: I'm in:/home/lain/Projects/a/b address correct! selected nodes: #(#<<file> name: "d" stat: #(25 2282509 16877 1 1000 998 0 0 1598874492 1597106934 1597106934 4096 0 directory 493 281439178 966470822 1597106934) path: "/home/lain/Projects/a/b/d"> #<<file> name: "e" stat: #(25 2282510 16877 1 1000 998 0 0 1598874492 1597106934 1597106934 4096 0 directory 493 281439178 966470822 1597106934) path: "/home/lain/Projects/a/b/e"> #<<file> name: "f" stat: #(25 2282511 16877 1 1000 998 0 0 1598874492 1597106934 1597106934 4096 0 directory 493 281439178 966470822 1597106934) path: "/home/lain/Projects/a/b/f"> #<<file> name: "g" stat: #(25 2282512 16877 1 1000 998 0 0 1598874492 1597106934 1597106934 4096 0 directory 493 281439178 966470822 1597106934) path: "/home/lain/Projects/a/b/g"> #<<file> name: "a" stat: #(25 2282506 16877 1 1000 998 0 4 1599584252 1597106923 1597106923 4096 0 directory 493 884844680 725745160 1597106923) path: "/home/lain/Projects/a">) As you can see the vector contains some information about nodes in the file system, I think that's fat enough not to do unneeded conversions, considering the vector could contain thousands of files. But maybe I'm wrong, overwriting the variable containing the vector can take much longer than your solution on lists, so I'm going to some benchmarks anyway.
typedef · 2020-09-08 16:31
>>20728 Yes, vectors are faster for accessing, but vector-append is more expensive than cons (the latter allocate a single cons-cell, the former might have to reallocate the entire vector). Of course real-world performance differences depend on the kind of content being sorted, and the implementation of vector-append.
Turner · 2020-09-12 22:45
Back on my way of making the modular DE/GUI toolkit using OOP. I need an advice for naming a variable in the file-manager class: scheme (define-class <file-manager> (<block>) (work-directory #:getter get-work-directory #:init-keyword #:work-directory #:allocation #:stored-message) (work-directory-changer #:getter get-work-directory #:init-keyword #:work-directory #:allocation #:basic-message)) I have one slot called work-directory, storing the current work directory of the file manager, but I need a second variable that will trigger refreshing of current nodes. The thing is, the variable when changed, will automatically run the refresh method. My current name candidate is "work-directory-changer". When modified, the variable will send a message containing the current work directory to other methods. What would be a good name? "Event-something", "handler"?
SHODAN · 2020-09-14 14:50
>>20787 Why is that a slot and not a generic function?
Dox · 2020-09-14 14:59
>>20832 >Why is that a slot and not a generic function? Because I made smart slots that act like methods - the #:allocation slot option changes the underlying logic of slot allocation. #:stored-message just sends a message to different threads/methods in my object - when work-directory changes, other threads are started and refresh current nodes (files and directories in the current work directory). https://www.gnu.org/software/guile/manual/html_node/Customizing-Class-Definition.html Why would I use generics? It wasn't well explained in the manual and I didn't find generics useful.
t · 2020-09-15 20:33
>>20833 >Why would I use generics? It wasn't well explained in the manual and I didn't find generics useful. Well, generic functions (at least in CLOS) allow for greater flexibility in terms of composition and delegation that just a function slot in a object, but as I don't know what Scheme you're using, I can't say much more.
Leto Atreides I · 2020-09-15 20:40
>>20858 >Well, generic functions (at least in CLOS) allow for greater flexibility in terms of composition and delegation that just a function slot in a object Guile's implementation of OOP (GOOPS), is based on The MetaObject protocol and is "very close in spirit to CLOS, the Common Lisp Object System". https://www.gnu.org/software/guile/manual/html_node/GOOPS.html If you could give me an example of such flexibility, I would be grateful.
word · 2020-09-16 18:24
Any good algorithm and data structure books in Lisp?
Cowboy · 2020-09-16 20:38
Someone here have tried Chicken (eg: Scheme compiled to C)? We have something similar but for Common Lisp instead? https://wiki.call-cc.org/
Masami Eiri · 2020-09-17 03:55
>>20861 Not the same guy but Generic functions are actually everywhere in Common Lisp. Consider division. If the arguments are integers, you get a rational, but if one of them is a floating point, you get one as a result (I don't know the exact implementation of division, but the idea is just that). Generic functions are broader in scope than inheritance, because they can be tied to unrelated classes. More important though, if you have a function whose behaviour depends on the class of more than one of it's arguments, to which class should it be tied to? Generic functions obviate the issue by not having methods bound to a specific class, and you can have your generic dispatch on any of a mix of matching sets of arguments, should you write the method to any specifics you need.
⍕ · 2020-09-17 16:04
So what's withLisp functions ending with a "-1"? Is there some kind of a convention to this?
XERXES · 2020-09-17 17:08
>>20886 The only two instances I know of in the spec that end with -1 are macroexpand-1 and boole-1. macroexpand-1 is like macroexpand, except it tries to expand the macro form you give it only once. boole-1 is an opcode variable for boole, such that (boole boole-1 myinteger-1 myinteger-2) returns myinteger-1. I also see examples like variable-1 and variable-2 in code, so my guess is that "-1" mainly means it's the first of *something*.
dup · 2020-09-18 07:55
>>20887 My bad, it doesn't have to have a dash too, in fact those two are not even that hard to understand. Take prin1, prog1 from the standard, but there are many more examples in real-world code. Do apropos "1$" in Emacs to get a list. I don't see the common thought here. My best guess would be that a trailing "1" should be read as "-helper".
Agent Jones · 2020-09-18 10:02
>>20877 I think ecl can translate to c.
Nanashi No Gombe · 2020-09-25 04:29
>old implementations vs new So I'm generally familiar with the whole Lisp type syntax but I haven't landed a specific flavor. Would it be best to go by the timeline and use the older implementations like Clisp, scheme, Machine lisp, etc. or to get into the more modern ones like Clojure and Racket, etc
Hitomi · 2020-09-25 14:26
>>20898 I don't think there is one single explanation for those. In prin1, the 1 is supposed to be a homoglyph of t: the function is very close to, but not quite the same as print, and they presumably couldn't think of a better name. The 1 in prog1, on the other hand, can be explained in the same way as for boole-1.
Crazy Jake · 2020-09-25 18:24
>>20972 If you want Lisp, learn Lisp. Scheme is the next best thing, but anything beyond that only bears a superficial resemblance
Motoko Kusanagi · 2020-09-26 20:19
By the way, when people like >>20988 say Lisp, they usually mean Common Lisp specifically.
Cutter · 2020-09-27 03:14
Has anyone tried GNU Artanis? How is it? It seems pretty neat cool but I don't know enough lisp yet.
Six · 2020-09-29 23:39
>>20900 >nice double 0's Let me ask here in this thread, which implementation of common lisp you all use? and why? I was using CLISP because it provide a nice repl where I can edit the commands and browse the history of last commands used etc.... I just find out that I can do this running sbcl or anyother using the program with 'rlwrap', and when running the CL implementation 'inside' emacs it will have history of commands and etc.
Motoko Kusanagi · 2020-10-01 04:55
>>15857 Common Lisp because I like my girls vanilla. Vim is the only true editor. (print -). Basic functions mostly, still new to this wonderful world. Don't know, please teach me senseis. Its a very elegant language with an immensely powerful abstraction [cells]. Its got very powerful metaprogramming features. 1 week total, loving every second. dunno. No, that's Python. I use it for fun. Cool lisp samples, cool ideas, cool resources, talking lisps, being lisps. What is a lisp machine? Probably not. Languages that need a machine built for their particular use will not go far. common lisp has nicieities for this (defun sum (a b) "Returns sum of two numbers" (+ a b)) dunno what those are. I'm considering investigating scheme in the future. For the moment clisp is all I need. Just clisp. Please don't make me delve into platonic essentialism. I only know defun
nil · 2020-10-01 19:23
>>21036 I like SBCL and ECL. Outside of Emacs (or simply in term-mode) you can use rlwrap to provide the same feature CLISP has built-in (which is actually the cause of its license too, iirc).
Liet Kynes · 2020-10-04 01:08
I'm trying to figure out how macros work in Common Lisp. This code results in an error, but I don't know why. What did I fuarrrk up? (defmacro increment (x) (setf x (+ 1 x))) (defvar a 1) (increment a)
Nell · 2020-10-04 02:28
>>21115 You need to quote the inner form. It has to do with the distinction between macros and functions.The context in which your macro is executed is not the one you think it is, which means defvar is not what you think it is when you're using the macro. You might want to give this a read: http://www.gigamonkeys.com/book/macros-defining-your-own.html (defmacro increment (x) `(setf ,x (+ 1 ,x))) (defvar a 1) (increment a) That will do what you expect, as it will only expand to the inner form and eval the x form into its actual value.
overriding · 2020-10-04 02:30
>>21116 * Which means your defvar is not doing what you think it is.
drop · 2020-10-04 02:37
>>21116 Thank you.
car · 2020-10-04 03:16
>>21115 >>21116 ...why are you using setf in the first place? You can do (defmacro increment (x) `(+ 1 ,x)) (defvar a 1) (increment a)
Gyula Kovacs · 2020-10-04 19:01
>>21119 That won't mutate/assign to the value cell. The lainon who asked the question probably intended this simply as a test to see how things work when doing that.
Neo · 2020-10-04 20:22
>>21119 >>21123 This reminds me... >>21115 You'd also probably want to use this instead. lisp (1+ ,x) instead of this. lisp (+ 1 ,x)
dup · 2020-10-07 03:35
I'm having trouble compiling standalone executables in ECL. lisp (compile-file "helloworld.lisp" :system-p t) (c:build-program "helloworld" :lisp-files '("helloworld.o")) There are no errors or warnings, but ./helloworld doesn't do anything except open ECL.
Koos van der Merwe · 2020-10-07 05:53
>>21160 Did you put some function at the bottom of your main file which calls your intended program flow (and quits once its done) & does the rest of everything? ECL doesn't really have a built-in thing for entry-points. You can do it the hacky way, or you can use ASDF. It has a bunch of nice features like this: https://common-lisp.net/project/asdf/asdf/The-defsystem-grammar.html#Entry-point-1 https://common-lisp.net/project/asdf/