freenode/#lisp - IRC Chatlog
Search
4:07:31
nij
How is an ffi designed? In particular, if I want to call a foreign abstract object (and play with it) in lisp, what should I do? Must I write a wrapper that models the foreign object in terms of a lisp object? Are there some known cases that won't work in lisp?
4:11:11
jcowan
THere are two ways to do it: write the C (or Blub) function using a specific signature that Lisp uses, or write a Lisp function that provides a C signature. In other words, either weird C glue or weird Lisp glue.
4:14:26
moon-child
most languages that are willing to speak to other languages do so using the c abi
4:15:22
White_Flame
FFIs are pretty complicated, in terms of GC walking the stack and knowing what's lisp vs C (or other), as well as needing native pointers & allocations represented in with lisp tagged values
4:15:30
moon-child
c++ abi has been implemented by non-c++ compilers twice as far as I know (d and raku). Both implementations are incomplete. C++ abi is huge and horrible. That's not a road you want to go down
4:17:13
White_Flame
you asked how it's _designed_. feel free to use them. don't try to design them as some introductory project
4:17:20
nij
Very interesting.. I wonder why languages are so hard to translate.. even in the realm of computer science.
4:18:09
White_Flame
every language has its own notion of memory allocation, how strings are structured, etc
4:18:51
moon-child
even languages with very similar type systems, like lua and js, you would probably run into trouble with
4:21:26
moon-child
remby96: _compiling_ one language to another isn't difficult. What's difficult is retaining the language-level semantics and type system as you do so in a way that makes interoperation practical
4:24:09
White_Flame
and what's difficult is sharing a single process address space with a different language's running binary stuff
4:24:26
loli
The type theory bit shouldn't be too bad, you are taking one formal mathematical system and compiling it to a stronger or weaker one. Idris, and Agda both compile down to Haskell this way
4:24:47
loli
Haskell and other languages compile down to eventually remove their type theory, or compile it down to an IR with weaker type theory
4:25:44
White_Flame
in fact, on the symbolics lisp machines, they had a C compiler that generated lisp processor machine code and played nicely with the system (if slow)
4:25:58
nij
> moon-child: "What's difficult is retaining the language-level semantics and type system as you do so in a way that makes interoperation practical" ;; <= this!
4:27:57
loli
there is interesting research with graded model types, where you can get a system F system out of it, so you could program in such a system and use languages with type systems in System F, or export to them in this way
4:28:15
saturn2
C programs on the lisp machine created a lisp byte-vector to function as the C program's "memory"
4:30:17
loli
moon-child: I'd have to drudge that up, but it comes out of better way to do QTT (think linear types on steroids)
4:30:56
pyc
Is it possible to do string interpolation within format using variable names, e.g. something along the lines of (format t "hello, {{name}}") ?
4:33:09
loli
does CL-INTERPOL change the " reader macro, or does it define a custom define function?
4:35:33
no-defun-allowed
I heard that they could run TeX on a Lisp machine using the C implementation, so it probably worked well enough.
4:36:50
no-defun-allowed
...though TeX is written in literate Pascal, and a conversion program generates the C code.
4:37:17
loli
why the conversion, do more systems just run C, or is it due to performance or maintainability concerns?
4:37:47
no-defun-allowed
Yeah, there are more systems with C compilers than Pascal - Lisp machines had both though.
4:38:15
loli
Is there a lot of literature on the Lisp machine, it seems a lot of that knowledge was lost with time
5:10:30
White_Flame
as far as symbolics goes, there's a lot of scans of both manuals & internal documents that are online now
5:11:09
White_Flame
there's no complete description of everything from the ground up, though, especially in terms of making a bootable image from scratch
5:12:46
loli
I guess i haven't been looking too hard then. I've found image literature lacking in general. Factor and MIT Scheme have some bits, but not much besides that
5:13:03
remby96
there was some website that had a lot ... I had to use it to get some info on the ibm 7094
6:50:44
susam
remby96: European Lisp Symposium - https://european-lisp-symposium.org/2021/index.html / https://www.twitch.tv/elsconf
8:48:01
minion
theothornhill, memo from nij: I've read the log again.. and I melted. Thanks so much :-D Let me know if I can help any.. (beware i'm just a noob)!
9:12:18
pyc
Is (let ((solutions nil) (metadata nil)) ...) a common coding style? Or do you prefer to write (let (solutions metadata) ...)
9:12:56
no-defun-allowed
Yes, the latter makes it look like SOLUTIONS and METADATA are not set to interesting values.
9:13:57
beach
pyc: More explicitly, the first means that you initialize those to some default values, or possibly to Boolean false.
9:15:23
splittist
pyc: to indicate that SOLUTIONS is an initially empty list, you'd say ...((solutions '())...
10:21:23
no-defun-allowed
Following a test in private messages, I think the -CL suffix → Common Lisp rule isn't random.
10:27:42
beach
lotuseater: ELS is currently the only international Lisp forum. There used to be an International Lisp Conference, it it might happen again, organized by the ALU (Association of Lisp Users). But I think the ALU is having problems recruiting (unpaid) staff.
10:29:33
beach
lotuseater: It doesn't matter much if there is one or two, nor what they are called. The only potentially problematic thing about the current situation is that ELS is always held in Europe, when it is a physical gathering. So people from other parts of the world are always the ones who have to travel far.
10:30:23
beach
lotuseater: But ELS (when it is in a physical place) has regular participants from Japan, USA, etc.
10:32:59
nij
Ah ELS is happening.. these two days are the two most busiest in this semester.. :-( it will be uploaded later?
10:33:38
lotuseater
and yes, i downloaded some pdfs from the last years and last year saw your some older talk about LOOP beach
10:33:57
beach
I guess a conference held in North America would have most participants take a flight, whereas in Europe, there are these things known as "trains", so it is probably better for the environment to hold conferences in Europe.
10:37:43
phoe
live and interactive programming using Lisp, interacting with music generators or video presentations or robots
10:52:43
no-defun-allowed
I wonder if (setf (arbitrary-arrows-library:-> nij pants pocket wallet note content) "Do this do that") works.
10:53:14
phoe
no-defun-allowed: binding-arrows should work, I've paid attention to define setf expanders that should work
10:55:37
nij
no-defun-allowed: hmm your method works? To get the content of note, we need (getf note 'content)?
10:55:49
no-defun-allowed
Some parts elided: (setf (arrows:-> *hayley* pocket note) "Test this code") *hayley* ⇒ #S(PERSON :POCKET #S(PAPER :NOTE "Test this code"))
10:56:01
jackdaniel
lotuseater: adding a nickname for the package and not importing anything is even better
10:56:16
_death
nij: there are libraries for that, like "access".. or you could just write your own.. but I think this pointer chasing is not a good sign.. check out Law of Demeter
10:56:19
no-defun-allowed
The elided part was precisely (defstruct (person (:conc-name "")) pocket) (defstruct (paper (:conc-name "")) note) (defvar *hayley* (make-person :pocket (make-paper :note "")))
10:56:45
no-defun-allowed
You're set if the accessors are actual functions, as in the arrow example.
10:57:27
nij
=>(setf (accesses place '(:a :type :alist) '(2 :type array) '(:b :type 'hash-table)) 3)
10:58:02
jmercouris
now that I am thinking about it your last name looks like "Kochman", which is German
10:59:48
lotuseater
i find that feature in the DrRacket IDE useful, it points to where a symbol comes from
11:00:03
nij
I wonder how access is implemented in principle. It doesn't use much macro.. but it doesn't seem to hack setf-expander either
11:04:28
nij
lotuseater: https://gist.github.com/phoe/2b63f33a2a4727a437403eceb7a6b4a3 this could b helpful
11:07:16
no-defun-allowed
Crikey, even the README for ACCESS shows off bad programming style, butchering the values of unexported symbols and slots.
11:09:43
no-defun-allowed
"It should however allow you to prototype more rapidly and change the backing data stores without having to change their access (ie I can switch from a plist to an alist and everything will continue to work)"
11:16:25
_death
there are libraries in other languages that do similar things, like lens (haskell) or specter (clojure).. but again, I think it's suspect
11:17:25
pyc
Is there no standard library function to do what (getf *map* (intern (string-upcase key) :keyword))) does, i.e. given a key as a string, look that up in plist and return its value?
11:17:48
pyc
that makes me think if I am misusing plist. perhaps plist is not meant for lookups where my lookup key is a string?
11:20:39
_death
pyc: interning should usually not be done willy-nilly.. sometimes a hash table mapping strings to whatever will do
11:22:02
pyc
My *map* is a quoted plist that has configuration data. It plays the role of what JSON or YAML might play in another language. Is it possible to create a hash as a literal in CL? With plist I have the advantage that I can create it as a single literal (quoted plist, e.g., '((:name "harry" :age 20) (:name "sally" :age 21) ...)
11:23:23
_death
pyc: for a single plist, there's alexandria:plist-hash-table.. you can always write a small function to translate from a form with nice syntax to whatever representation
11:24:26
nij
so.. is access (cl) bad style? it's hard for newb to tell us cl stuff are usually under documented
11:25:35
pyc
_death: thanks. let me revisit Practical Common Lisp. I think it has an example of what I am trying to do in its 2nd chapter (a simple database). The author did it without using any external lib, so it may have something helpful for my situation.
11:26:25
_death
pyc: sure, you can easily write plist-hash-table.. I just gave a reference so you can look it up
11:27:06
no-defun-allowed
Very much so - if you want to get at or set some value in an object, then you should define an accessor function. That makes it actually possible to replace the representation, and to read e.g. (pocket nij) instead of (getf nij 'pocket).
11:27:42
no-defun-allowed
And then POCKET can signal an error if the input is malformed, whereas (getf '() 'pocket) would return NIL and the error would be blamed on another function.
11:35:16
pyc
_death: Do you have an opinion on this way of solving the problem: (defvar *map* '(:a "apple" :b "ball")) (getf *map* (find-symbol (string-upcase "a") "KEYWORD")) ?
11:38:09
_death
pyc: when I need to translate from "external" strings to a fixed set of keywords, I don't use something as general as find-symbol
12:13:33
engblom
I have a long string with line-feed (so actually several lines of text). Now I need to find the first word on the line containing a string I searching for. Are there any ready functions I can use for this?
12:15:03
flip214
engblom: there are string-trim functions to remove whitespace. If you like regular expressions, there's a library CL-PPCRE.
12:34:56
beach
engblom: I would probably start by splitting the string using SPLIT-SEQUENCE (library). Then I would use SEARCH to determine whether the substring is present. Finally, I would use SUBSEQ to extract the string you want.
12:46:57
pjb
engblom: yes: (let* ((pos (search target text)) (bol (position #\linefeed text :end pos :from-end t))) (subseq text bol (position-if-not (function alpha-char-p) text :start bol)))
12:49:16
engblom
I am trying to use (string-trim '(#\Space #\Tab #\Newline) " ... a string with extra spaces and line feeds ...") but for some reason it does not trim anything.
12:51:49
pjb
engblom: note: there are two ASCII control codes: Carriage Return CR = 13, and Line Feed LF = 10. They are used to indicate new lines: CR alone on Macintosh, CR LF on MS-DOS and MS-Windows, LF alone on unix systems. Common Lisp abstract this away, by defining a #\newline character that is normally used to separate lines.
12:52:45
pjb
engblom: now, it is possible that a given implementation uses (eql #\newline #\return) or (eq #\newline #\linefeed) (or some other characters, for example, in ISO-8859-1 there's a NEL control code, and in unicode there are several code points that can be used.
12:53:36
pjb
engblom: but you probably meant a newline, and then ~% could be used with format or a literal new line could be inserted in a multi-line string literal.
12:54:31
pjb
engblom: this is why it is important to have a precise terminology, that you can acquire by reading the Hyperspec. http://www.lispworks.com/documentation/HyperSpec/Body/13_ag.htm
12:58:02
pjb
engblom: note that only #\space, and #\newline are standard character names. The other non-graphic character names #\rubout #\page #\tab #\backspace #\return #\linefeed are only semi-standard: they may not exist if the implementation doesn't have the codes representing them. For example, in EBCDIC, some of them wouldn't exist (on the other hand, EBCDIC has a NEL code too, for a direct mapping to #\newline).
12:58:37
pjb
So my code above, using #\linefeed, is not conforming: on an implementation without #\linefeed, it would fail.
12:58:58
pjb
I should have written something like #+has-line-feed #\linefeed #-has-line-feed #\newline perhaps?
13:00:53
pjb
engblom: see https://github.com/informatimago/lisp/blob/master/common-lisp/cesarum/character.lisp
13:04:55
engblom
I tried it, but sadly it fails: it gives an empty string in my case. I wonder if it is because of the linefeed being strange. When I use print on the string it puts ^M where the linefeeds are.
13:05:51
engblom
beach: Nope, but this is information fetched through telnet out of some network equipment.
13:05:51
splittist
EBCDIC performs two vital functions: (a) keeping IBM's Big Iron functioning into its nth decade; and (b) giving CL language lawyers something to talk about.
13:07:01
beach
engblom: I think you really need to take the two or more suggestions and experiment with them. It is hard to give you all the details for all the variations of the problem here on IRC.
13:07:52
engblom
Yes, I will have to experiment myself. The strange thing is that split-sequence with #\Linefeed works well.
13:12:11
pjb
engblom: engblom it's improbable that your lisp strings contain both return and linefeed. Usually they're converted into a newline when reading, and converted back when writing.
13:13:12
pjb
If your string contains them I would suggest 1- select the right :external-format to avoid reading them. 2- removing them from your string (if you have newlines with them), or 3- replace them with newlines.
13:14:17
pjb
If you receive the data in binary and convert it to strings, then you need to handle the 13 10 bytes yourself and replace them with a #\newline character.
13:29:21
pjb
engblom: or just use com.informatimago.common-lisp.cesarum.ascii:ascii-string https://termbin.com/x9bv2
14:36:22
lukego
hey are the lightning demo slots all booked for ELS tomorrow? if there's space I could do a couple of minutes' demo of my SLIME backend for McCLIM. This is a new project that I'm hoping to finish and ship quickly.
14:47:38
jeosol
Good references to your work that aided implementations of CLOS related functionality in several implementations; Congrats
15:08:07
brandflake11
Hello all, there is a small function I am working on that is not making sense to me. I think it stems from my understanding of how variables work inside DEFUN and LOOP. Would anyone be interested in looking at the code?: https://pastebin.com/TMNvKvc7
15:13:53
semz
fwiw you can insert raw/ into the url to get the raw text, like this https://pastebin.com/raw/TMNvKvc7
15:16:27
brandflake11
Bike: When I do use push outside of a loop though, I can do that and it will append and make a list
15:18:55
brandflake11
Bike: Interesting. It works with this: (defparameter listy '(nil)) and then (push 1 (nth 0 listy))
15:19:51
Bike
No, it doesn't. Try doing (push 2 (nth 0 *listy*)) afterwards. You again end up with a list of one element.
15:21:05
Bike
What you probably want to do in your code is bind loop-list to nil instead of '(nil), and do (push loop-var loop-list) instead of the nth. Why are you doing the nth?
15:21:52
Bike
No, you don't. Look at the value of *listy*. Type *listy* into your repl and see what its value is.
15:22:16
Bike
PUSH returns the new list, i.e. _the element of *listy* that you pushed to_, rather than *listy* itself.
15:23:22
splittist
brandflake11: although people say you stop seeing the parens after you get used to lisp, but they're still important (: (nil) is different from () (= nil )
15:26:32
Bike
other things in your code... it still doesn't work with the fix i suggest, because the last length is not pushed; you probably want a finally clause in there