freenode/#lisp - IRC Chatlog
Search
21:42:42
johnnymaster
(defun test-function (fn tree &optional init-val) (cond ((null tree) init-val) ((atom tree) (list tree)) (t (mapcan #'(lambda (x) (test-function fn x init-val)) tree))))
21:43:13
johnnymaster
With this I am able to get the list of elements from the tree, how can I use reduce to apply the function the the elements now?
21:43:54
johnnymaster
I'm hoping to keep it within one function (not use a helper) and hopefully make use of reduce
21:48:23
k-stz
johnnymaster: you implemented a function that flattens a list so far, now all you have to do is call (apply fn <on-the-result>)
21:49:22
johnnymaster
Yup, but given that my function keeps recursively calling itself, how do I get the list and then apply fn to it?
21:50:42
k-stz
well I'd make to functions since flatten is useful on its own, but if you insist you can make it a local-function using `LABELS'
21:59:45
johnnymaster
(defun reduce-tree (fn tree &optional init-val) (labels ((reduce-tree-helper (x) (cond ((null x) nil) ((atom tree) (list x)) (t (mapcan #'reduce-tree-helper x))))) (reduce fn (cons init-val (reduce-tree-helper tree)))))
22:16:53
Josh_2
I have a list of words and I want a an array for every length of word which contains only words of that length, but I don't want to write (let <55 arrays etc>)
22:28:06
Josh_2
This shows what I'm trying to do I may be completely wrong though https://pastebin.com/cQyM8jNj
22:40:46
pjb
Josh_2: if you have 55 arrays, then a good idea is to put them in a vector (make-array 55 :initial-contents (list array1 array2 … array55))
22:42:22
pjb
Josh_2: or of course; (map-into (make-array 55) (lambda () (make-array 0 :adjustable t :fill-pointer t)))
22:49:48
aeth
What's the most efficient way to go over a list that might be dotted list and then de-dot it?
22:50:25
aeth
I can't use dolist or loop for foo in list or the other things because they'll error at the last element
22:52:07
aeth
What I want is I want to take a list, and if it's a dotted list at the last element, turn that last element into `(&rest ,element) and otherwise just leave the list unchanged (probably copying the whole thing every time, I guess). i.e. turning a Scheme lambda list into a CL lambda list. e.g. (x y . z) => (x y &rest z)
22:52:24
aeth
There's also a case where it's not a list at all, in which case it'd just become (&rest z) but that's trivial
22:53:31
pjb
(loop for (x . rest) on '(1 2 3 . 4) if (null rest) then do (loop-finish) else if (atom rest) then do (process x) (process rest) (loop-finish) else do (process x))
22:54:26
aeth
Xach: I'm writing a Scheme in CL taking as many shortcuts as possible. It's a problem I come back to from time to time. The biggest shortcut of all is to implement a Scheme lambda as a CL lambda with a continuation parameter at the front and run it in continuation-passing-style with a trampoline that ensures tail recursion.
22:55:40
Xach
aeth: ok. i ask because destructuring-bind, for example, accepts dotted lists for destrucutring
22:55:58
pjb
aeth: of course, you can just use (com.informatimago.common-lisp.cesarum.list:list-elements '(1 2 3 . 4)) #| --> (1 2 3 4) ; 3 ; nil |#
22:56:20
aeth
I can define Scheme procedures in terms of foreign CL functions through a macro that emulates Scheme's define syntax, e.g. (define-scheme-procedure (+ &rest numbers) (apply #'+ numbers)) but to make that fully consistent it should use a Scheme lambda list, e.g. (define-scheme-procedure (+ . numbers) (apply #'+ numbers))
22:58:02
aeth
And I handle the nil vs. (#f and '()) issue by having two macros, define-scheme-procedure and define-scheme-predicate, where the latter replaces nil with :false (which might have to be something else if I add keyword support to the Scheme)
22:59:52
aeth
This way, the Scheme can use any CL code as a Scheme procedure as long as someone writes a trivial wrapper macro for it. (And the other way around would work even easier since the Scheme procedures are just CL lambdas with a continuation parameter and guaranteed TCO)
23:00:43
aeth
Xach: I have looked at Pseudoscheme, but it takes shortcuts that are legal for r4rs that aren't legal for r7rs (the languages have diverged more) and it doesn't fully implement r4rs because it's not about accuracy of implementation
23:02:53
aeth
Iirc (it's been a while since I read the source), I think Pseudoscheme just uses the CL reader, which will have two issues. It'll permit things that are legal in CL but not legal in Scheme, and it won't read things that are legal in Scheme but are not legal in CL. The latter is the larger problem, and it only gets worse with each rnrs.
23:04:03
aeth
There are actually subtle edge cases even in the s-expression representation themselves, e.g. Scheme treats '(. x) as legal and reads it as x
23:04:24
aeth
That probably simplifies their lambda list representation, which seems odd from a CL perspective
23:14:43
Xach
ACTION recalls the criticism that scheme syntax is defined on character syntax rather than objects
23:23:12
pjb
aeth: obviously, you need to have your own scheme reader macros, or even a whole reader.
23:28:46
aeth
pjb: Well, not really a whole reader, what will happen is I'll read enough to see if I can use the CL reader, and then read it if I can, and if I can't I'll have to fall back to my own stuff.
23:29:11
aeth
And they're not mutually exclusive. Once I write a read, I can use that read in a reader macro, for inline Scheme
0:04:29
dmiles
oh, so it matters most because it comes down to :include other and your boolean example
0:09:12
dmiles
i guess what i was thinking is all teh return values of typeof might have a system class
0:15:45
pjb
so you're asking if an implementation could provide a system class BOOLEAN corresponding to the type BOOLEAN and containing only T And NIL, with as superclass SYMBOL and as subclass NULL.
0:17:17
dmiles
maybe i meant the opposite.. NULL as a subclass of Symbol and Boolean a subclass of Symbol
0:18:48
pjb
"Individual implementations may be extended to define other type specifiers to have a corresponding class. Individual implementations may be extended to add other subclass relationships and to add other elements to the class precedence lists as long as they do not violate the type relationships and disjointness requirements specified by this standard."
0:21:02
pjb
Since it wouldn't be a standard class, conforming programs would avoid using it. Do you think it would be useful?
0:22:07
dmiles
pjh: the only use it give me is save maybe 10 lines of code .. so i think i wont create that exra trouble fo a user by grabing up any nsamespace
0:22:50
pjb
you can use EQL : (defmethod foo ((objc (eql t))) 'true) (defmethod foo ((objc null)) 'false)
0:27:55
pjb
as an implementer you can study 11.1.2.1.1 and 11.1.2.1.2 to see what you can and cannot do with the CL symbols.
0:31:18
dmiles
it woiuld ve a ton of work on the part of an implementor to actually prevent the user for doing most of that
0:47:52
pjb
Do you support (tagbody (mapcar (lambda (x) (if (zerop x) (go :end)) x) '(1 2 0 3 4)) :end) #| --> nil |#
0:48:29
pjb
Similarly (block :foo (mapcar (lambda (x) (if (zerop x) (return-from :foo 42)) x) '(1 2 0 3 4))) #| --> 42 |#
0:50:10
pjb
(tagbody (unwind-protect (mapcar (lambda (x) (if (zerop x) (go :end)) x) '(1 2 0 3 4)) (print 'foo)) :end) #| foo --> nil |# (block :foo (unwind-protect (mapcar (lambda (x) (if (zerop x) (return-from :foo 42)) x) '(1 2 0 3 4)) (print 'foo))) #| foo --> 42 |#
0:53:02
dmiles
but it is really easy for me (i feel compelled constantly) to write non backtracking code
0:54:21
dmiles
just be it allows one to do non standard things that are normally hard in prolog (since its always ready to unwind
0:57:22
dmiles
just because swi-prolog allows me to do non standard things that are normally hard, if not impossible, in other prologs .. i just have to keep reminding myself throw/1 can be called
1:17:39
dmiles
mentally it is hard form to picture that when i call a predicate from another predicate how that constitutes backing out.. it *looks* like its diving in deeper
1:18:59
dmiles
yet the grandparent frame is already collected by the time you enter the grandchild frame
1:33:55
dmiles
the wierdness is that the second example @ http://clhs.lisp.se/Body/s_tagbod.htm works because the "(go out)" is calling a whole separated compiled subroutine that only contains "(prin1 n)"
1:38:37
aeth
pjb: Thanks for the help, I think I'm going to go with this: (loop for x on '(1 2 3 4 . 5) by (lambda (x) (let ((next (cdr x))) (if (not (listp next)) `(&rest ,next) next))) collect (car x))
1:39:30
aeth
This turns a Scheme-style dotted lambda list into the CL equivalent, i.e. (x y z . foo) => (x y z &rest foo) as long as the special case of not a list at all is dealt with first.
1:41:33
aeth
(I use (not (listp next)) instead of (atom next) because nil is an atom and that'll blow up the list into an infinite loop)
1:43:41
stacksmith
G'day... Can someone tell me what happened to uiop:launch-program? What is a good way to run another program (asynchronously) and get its stdin and stdout?
3:16:32
rumbler31
if you're trying to use ccl, I think ccl bundles an old version of asdf, so you might have to load a recent version to get it?
4:10:09
resttime
Sup, I've been writing small bits of Common Lisp to test a C++ daemon I'm writing that's going to be on a satellite which got me imagining lisp in space so I'm curious if it's possible to protect against random bitflips in space due to radiation with whatever is available.
4:11:50
resttime
Like could a random bitflip screw up a type and cause devastating errors throughout the whole lisp image or make the garbage collector delete the wrong memory?
4:13:04
resttime
An example to kind of protect against this in C is to represent a flag for example is reprsentating ON/OFF with a UINT16 instead of a single bit
4:14:15
resttime
But anyways, I don't know anything about this for lisp, like is it enough to use T and Nil?
4:15:39
Bike
you'd have to specifically think about it. i mean, like you could do the popcnt booleans in lisp as well
4:16:44
resttime
Errr but again this is going into implentation territory I dunno about so I'm here to ask :)
4:17:33
antonv
hi, who knows, what cl-tbree version is better / newer: https://sourceforge.net/projects/cl-btree/ or https://github.com/danlentz/cl-btree ?
4:18:14
pjb
resttime: you can write your own implementation, or patch an existing implementation, to add redundancy in the internal representations.
4:18:55
resttime
pjb: Supposedly yeah, but still protection is pretty important that stuff is still implemented like that. Example being multiple copies of data of polling data (there's been discussion about something like partitioning to store multiple copise of samefile on disk etc on satellite)
4:20:27
resttime
I wonder if there's some source of the lisp that ran on other space hardware and/or technical specifications of them somewhere
4:20:29
pjb
For example, there have been lisp implementations where there were no (obvious) type tag. Instead, data of a given type was stored all in the same memory page. So the type depended on the address. Then you would have to protect bits in pointers!
4:22:23
pjb
resttime: but seriously, it shouldn't be too hard to patch an implementation to do that.
4:26:36
Zhivago
I like the dylan approach which had the type tags point at the objects, allowing the tags to be elided where static inference was sufficient.
4:40:07
resttime
This seems like the right place to snoop around in lol: https://github.com/sbcl/sbcl/blob/master/src/compiler/generic/early-objdef.lisp
4:53:21
resttime
I probably need to rethink the premise :/ there's really only so much redundancy that can be added on before getting pedantic.
4:54:57
resttime
There's some C code which does do the whole bitflip protection thing so I'll ask those guys why they decided why they put it there
5:01:49
resttime
harovali1: You can check out roswell if you'd like, it's an implementation manager+more if the archlinux support isn't good enough
6:16:22
turkja
trying to get linedit installed on a debian box... what heck is going on, any idea? I get errors like this: "Just performed compiling #<MADEIRA-PORT "linedit" "ports" "ccl"> but failed to mark it done"
6:26:53
turkja
Just performed compiling #<MADEIRA-PORT "linedit" "ports" "ccl"> but failed to mark it done.
7:18:50
beach
greyavenger: It is easy to choose the wrong tools, so if you need help, you should say so.
7:44:19
Shinmera
stacksmith: uiop:launch-program works fine enough for async processes. I recently switched simple-inferiors to use it instead of external-program.