IRC channel logs
2023-04-16.log
back to list of logs
<cow_2001>awww, i can't make guile go into an infinite loop by walking along cyclic "lists" <cow_2001>if i write my own last-pair it goes on and on <RhodiumToad>the builtin last-pair is explicitly documented as returning error for cyclic structures <cow_2001>i first assumed it was built in behaviour but then ,describe last-pair proved otherwise <RhodiumToad>so anything that checks its args for list? rather than pair?/null? will error on cyclics <cow_2001>i've recently learned how they check for cycles and it's *clever* :| <cow_2001>let two pointers walk along the list, one at +1 strides the other at +2. if they meet, it's cyclic, otherwise, not <cow_2001>RhodiumToad: your notes go into my sicp solutions! <RhodiumToad>(I don't know if the scheme spec requires list? to be false for cyclics) <cow_2001> https://index.scheme.org says "Returns #t if obj is a list. Otherwise, it returns #f. By definition, all lists have finite length and are terminated by the empty list." <RhodiumToad>the tortoise/hair algorithm requires only two pointers regardless of the list length <cow_2001>or! right! i forgot that an improper list is one where the cdr of the last pair is not '(), but the last element of the list <cow_2001>ah, no need to keep record of which pairs you've already visited, which would have been O(n), but just a O(1) tortoise and hare <cow_2001>(last-pair '(1 2 . 3)) returns (1 . 3), so it only checks for cyclics <RhodiumToad>most functions that make sense on improper lists do in fact accept them <RhodiumToad>looking at the code, last-pair does the hare/tortoise algorithm itself rather than calling list? first <cow_2001>oh right. '(1 2 3) is in the static (constant?) part of memory town <cow_2001>no, that's not it? i just went into guile and tried it and it didn't crash <cow_2001>(define a '(1 2 3)) RET (set-cdr! a 8) RET a RET and we see $1 = (1 . 8) <flatwhatson>sure, your paste example doesn't crash in the repl either <cow_2001>trying the same in a file and it doesn't crash <flatwhatson>modifying constant pairs is wrong, regardless of how reliably it crashes <cow_2001>okay! got it! (define a '(1)) (set-cdr! a 2) segfaults, but (define b '(1 2)) (set-cdr! b 3) does not <cow_2001>wait, i don't need that deepest null check <dokma>Does this work for you fellas? <dokma>(use-modules (web socket client)) <dokma>(make-websocket "ws:ws.vi-server.org") <dokma>Or am I misunderstanding how it should be used? <dokma>Is there perhaps official support for websockets in Guile 3.0 ??