freenode/#lisp - IRC Chatlog
Search
18:51:26
Bike
you mean like a local recursive function? because if it's globally defined you can just treat a recursive call like any other call to a global function
18:53:10
Bike
you can implement letrec as basically binding the variables to some kind of unbound marker, evaluating the forms in that environment, then modifying the environment to have the values of the forms for those variables.
18:54:50
chris4197
THAT was the video I thought of. Sadly it is in clojure. https://www.youtube.com/watch?v=2wPS_6oSD6k
21:25:32
hello80493485039
trying to implement a function similar to "positions" that takes in a number N and a list L and returns all the indices of N in L
21:26:09
Bike
hello80493485039: append does not have side effects like you seem to think, and it works with lists generally. maybe you want push.
21:29:12
hello80493485039
whhat is the lisp way of finding the indices of all N in a list e.g. suppose n = 2, list = (2 3 1 4 2) then result = (0 4)
21:29:52
Bike
there are innumerable ways to write it yourself, of course. your code seems like it will be reasonable once it's fixed up
21:30:20
Bike
i personally would do (loop for i from 0 for element in list when (eql element to-find) collect i)
21:30:43
dialectic
(loop for item in list for i from 0 when ... grrr ok bike, steal all the thunder.
21:31:54
Bike
with tail recursion it adds up to about the same, except of course yours collects backwards
21:33:49
Fare
asdf_asdf_asdf, use uiop to exit with a code, or run-program to run a program and check its exit code.
21:39:56
hello80493485039
Bike what do u think about this? https://gist.github.com/aamirsahmad/c9af6e26e166ece00f23d946d66b3670
21:43:45
Bike
list indices start at 0, not 1. using = means the list can only have numbers. using nth each iteration is less efficient than iterating over the elements simultaneously.
22:02:14
dialectic
Also my recursive version never terminates because I forgot to take the cdr of the list. Loop spoiled me.
22:04:55
dialectic
The only thing I ever use tail recursion for is statemachines, and even then, 90% of the state machines I have ever written are TAGBODY and GO
22:09:41
dialectic
Using recursion is a pedagogical thing. It is somewhat instructive, maybe even enlightening, but a real language for looping is much better for real use.
22:27:25
markasoftware
i'm not sure about that, i tend to find that as a loop gets more complex, it actually gets easier to implement with recursion and more difficult to keep as a loop
22:46:31
edgar-rft
Stupidly I can't remember where i read the following sentence: "Loop was designed to provide simple solutions for simple problems. As soon as things become more complex it's most often easier to implement solution in more complex code."
23:45:27
seok
Thanks Bike and PJB I fixed the code, works with a function I had missed a parantheses
23:55:39
no-defun-allowed
random-nick: (remove-if-not #'listen streams) -> streams-ready-to-be-read-from