libera/#commonlisp - IRC Chatlog
Search
17:33:27
nick3000
Does anyone know if there is a simple way to create a 'bivalent' (I think I'm using that word right) in-memory stream with flexi streams or some other library? I was thinking some kind of class that just writes to one stream and reads from another. I want that because I am unit-testing some TCP-socket code that reads and writes to a socket. I was thinking if that was super hard I would just pass my server code two different streams,
17:48:19
nick3000
THe flexistream manual does use the word 'bivalent' but when I click the link to find a definition it does not point to anything with the word 'bivalent'.
17:51:20
nick3000
Okay so that is what I was looking for, if there was a library that allowed me to take an input and output stream and wrap them into a single bidirectional stream.
17:57:25
Nilby
but unfortunately I haven't published my text drawing program because it's not an emacs yet
17:59:42
Nilby
synonym stream is like an alias to another stream, e.g. so you can have a stream that is actually writes to whatever *standard-output* is set to
17:59:48
pjb
nick3000: for a bidirectional stream, you need two streams, (four ends) and connect their ends with make-two-way-stream.
19:03:57
CptKirk
I have a list of "0 1" and I want to repeatedly cycle over that list say, 10 times, collecting items from the list. say 0 1 0 1 0 1 0 1 0 1
19:04:55
CptKirk
I can of course write this in raw lisp, but I'm looking for a loop macro that does this if there is one
19:12:20
lisp123__
But append is highly inefficient, just wanted to show that its a useful keyword in the loop macro
19:15:08
yitzi
If you are not trying to do processing along the way (apply #'append (make-list 10 :initial-element '(0 1)))
19:16:42
rotateq
CptKirk: in general the #n= is for labeling a form and with #n# you can recall it so that the reader sets the form in at that place too
19:18:57
Alfr
CptKirk, for a non-circular list L which you are allowed to modify: (setf (cdr (last L)) L)
19:24:21
Nilby
It's just a copy and paste. The reader just copies #1 where it sees #1#. The cons cell is already created before it's contents are put in.
19:24:44
Alfr
CptKirk, it's not clear what you're asking. But as CALL-ARGUMENTS-LIMIT is an integer, it's finite, thus a circular list can't be a function call form.
19:26:46
CptKirk
@alfr I'm asking at what time does it expand the #1# reference because clearly it can't do that infinitely
19:30:48
Alfr
CptKirk, it doesn't. A proper list is either nil or a cons whose cdr is a proper list.
19:31:55
Alfr
CptKirk, you get a circular list if you modify a cdr of a cons in a list to refer to some preceding cons of that list.
19:34:04
Nilby
Here's without the reader trick:(let* ((l (list 0 1))) (setf (cdr (last l)) l) (loop for i in l repeat 10 collect i))
19:41:45
newlispurr
How do I put imports in a file in Common Lisp? (I'm using Portacle) If I put (ql:quickload :local-time) on top of my .lisp file, and run C-c C-k (compile and load) it doesn't work, but if run (ql:quickload :local-time) in the SLIME REPL and then C-c C-k again it works.
19:42:15
newlispurr
What should I put in my .lisp file so I don't have to run (ql:quickload :local-time) in the REPL every time I restart Emacs?
21:01:03
Alfr
pjb, sure when I make one. Some of my stuff are just single files in PATH, that's what I assumed he wanted such behavior.
21:01:28
pjb
CptKirk: you cannot have circular structures in the source code, but you can have them in literal objects (quoted or self-evaluating).
21:02:02
pjb
Alfr: so you explained how to use eval-when to put quicklisp in source file. Which is what he shouldn't be doing.
21:03:23
pjb
CptKirk: the source code is processed by the compiler. if you use structuring sharing, including circular structures, then the compiler may not terminate, or have other bugs because of the sharing. But this doesn't matter for data, which is data, and is not processed by the compiler.
21:04:02
pjb
CptKirk: the only processing of literal data the compiler performs, is possibly identifying common substructures in literals, and share them in the object file.
21:04:57
Alfr
pjb, I never said it's best practice. And I usually use it with load-system only -- not ql.
21:05:02
pjb
CptKirk: note: I use the term structure in a general way here, because #=/## can be used across cons cells, vectors, structure objects, and other read forms.
21:06:01
pjb
Alfr: the penalty is that you might eventually have to maintain the bad code he writes…
23:00:13
hendursaga
How should I go about typing a function that returns the output of an already-typed function? Just "function" and the rest is inferred or what?
23:04:59
rotateq
then an example could be when you want to abbreviate EXPT with ^, (setf (symbol-function '^) #'expt) and that probably wrapping in an eval-when. or with FDEFINITION instead of SYMBOL-FUNCTION, maybe to that point someone can say more detailed difference
23:06:09
hendursaga
Like, the first function calls the second one in a specialized way and returns the result, thus the return type is the same for both.
23:06:43
rotateq
noticeable is when you then do (fmakunbound 'expt) or just shadowing it in your package, the ^ is still usable
23:07:32
hendursaga
I'll just assume it infers it. Otherwise CL's typing system would seem really weak.
23:10:24
hendursaga
In other words, the input types differ, but the output types should be the same.
23:11:05
hendursaga
Like, say, a function that returned the area of a rectangle and one that returned the area for a square.
23:13:10
rotateq
not really different from, say, the INTEGER, but this is a built-in class and normally the user defined ones are standard-classes
23:13:35
hendursaga
So how would I type square so that the output types part is the same as rectangle?
23:21:40
cuz
Would anyone mind helping me understand how (defun foo ()) is different from (defparamter foo (lambda ()))
23:22:50
Alfr
hendursaga, consider: (defun f () 'foo) (defun g () (f)) I know of no implementation which derives that g will return a symbol.
23:22:54
pjb
1. During the execution of any reference to the declared variable within the scope of the declaration, the consequences are undefined if the value of the declared variable is not of the declared type.
23:22:55
pjb
2. During the execution of any setq of the declared variable within the scope of the declaration, the consequences are undefined if the newly assigned value of the declared variable is not of the declared type.
23:22:55
pjb
3. At the moment the scope of the declaration is entered, the consequences are undefined if the value of the declared variable is not of the declared type.
23:23:24
pjb
Therefore you really do not want to use type declarations since the only thing they do, is make your code more undefined!
23:23:45
Alfr
hendursaga, most likely because you could later (defun f () 42); so that'd would then have to be fixed up.
23:24:12
rotateq
cuz: a first thing that comes to my mind is, with DEFUN you also define a block you can explicitely return from
23:25:12
cuz
I'm making a package and I want to split it into different files. I have this foo thing that I want to reference in a seperate file than the one it is defined. When I try to reference it while using defun I get an undefined variable warning from slime...
23:25:19
pjb
The specifications of FTYPE is less precise, but I think we can safely infer the same kind of undefinedness will occur if you declare ftype of your functios.
23:26:33
pjb
hendursaga: furthermore, what is the type of the function f of Alfr? It returns 42. different implementations say 42 is of type: (INTEGER 0 2147483647) (INTEGER 0 1152921504606846975) (INTEGER 0 1099511627775) (INTEGER 42 42) (INTEGER 0 4611686018427387903)
23:27:04
pjb
hendursaga: If you have an implementatation for which it's (INTEGER 42 42) and you want to say that g is of same type, then g can only return 42 !!!
23:27:39
rotateq
cuz: okay but you can in the second file put atop (in-package :my-pkg) and specify in your .asd that the second depends on the first where the function foo is initially defined. or do i miss something?
23:28:09
Alfr
pjb, doesn't matter for that example definitely not symbol, as f initially gave back foo.
23:29:23
cuz
rotateq: yeah thats exactly what i'm doing but I get a warning if I use defun and no warning with defparameter. It's very odd imo, and I was begining to think there might be a different table for functions and parameters?
23:32:10
pjb
Type inference is not specified by the language. It's a technique a compiler can use, just like data flow or any other technique. I'm not sure the programmer has to make anything of it, apart from the fact that the human programmers make reason about the program in a similar way. Ie. we can infer that g returns foo (assuming the original f definition), but the human programmer must also assume that g may return anything else, because
23:32:10
pjb
it can be redefined at run-time, or f can be redefined at run-time, or there may have been some non-standard reader macro on #\' or on #\f that makes 'foo read as something entirely different.
23:32:18
moon-child
rather than (defun f ...), you might also say (setf (symbol-function 'f) (lambda ...))
23:34:36
pjb
It would be better to think in terms of classes. (but the details of class hierarchies are also implementation dependent).
23:35:31
pjb
(class-name (class-of 42)) returns fixnum in 4 implementations, and integer in 1. fixnum is NOT a class defined in the CL standard!
23:36:10
pjb
(but it's not against the standard to have a fixnum class as subclass of integer, so those implementation remain conforming).
23:36:23
rotateq
pjb: yeah or the length in bits of a fixnum. on my machine for example: SBCL -> 62, CCL -> 60
23:36:52
pjb
hendursaga: hence again, even if classes are better than types, you should probably forget about them!
23:38:40
rotateq
i got the difference of both like so in my head: DECLARE if it shall stay that type till the end, and CHECK-TYPE to check if it's at that point the type which can also vary later on
23:41:27
rotateq
after all, for prototyping things such too narrow thoughts just stand in productivity's way
23:43:02
rotateq
it's not the "oh now we are going to a for loop, so specify the 'int i;' before" :P