IRC channel logs

2016-05-29.log

back to list of logs

<ijp>looking back on my fectors library, that sort of semi-persistent data structure is actually a really niche thing to want
<ijp>although there isn't such a function, it's only really useful when you *need* and *use* undo
<ijp>since there is no way to make the history that is stored be "compacted" on gc
<ijp>although I suppose I could add a -copy function
<ijp>and that's a *really* weird thing to put in a library that purports to be "persistent"
<ijp>anyway, ho hum
<Baldtoenails>So when you use define-macro/defmacro but say return (list #'+ 1 2 3) instead of (list '+ 1 2 3) it becomes hygienic, I assume this is a unction of how (datum->syntax context datum) works on data that are already syntax objects, is this intended documented design on defmacro's part or just an implementation hack?
<mark_weaver>Baldtoenails: it's not specifically intended, and I would not assume that this behavior will remain
<mark_weaver>I would also advise against using define-macro/defmacro in any new code.
<Baldtoenails>mark_weaver, ah yes, and what about that (datum->syntax context identifier) basically returns identifier if it's an identifier?
<mark_weaver>syntax-case macros are strictly more powerful
<Baldtoenails>Well, I don't use it, I ust observed that datum->syntax worked like that and then felt like trying it in define-macro to see if that would work because I assumed it just used a simple unpack->repack logic and to my amusesment it did.
<Baldtoenails>R6RS seems pretty vague about what shoul happen when datum->syntax is applied to what is already syntax.
<mark_weaver>yeah, that seems outside of its intended usage
<mark_weaver>I don't know the answer to your second question, it would require more investigation and/or thought.
<mark_weaver>but I would avoid writing code that relies on that behavior
<mark_weaver>it might conceivably be a security-relevant question
<daviid``>I need to read a file and return a vector of unsigned-byte 8
<mark_weaver>existing code might assume that 'datum->syntax' can only produce references to identifiers visible in the lexical environment of 'template-id'.
<daviid``>never done that before, any hint?
<mark_weaver>daviid``: get-bytevector-n
<daviid``>mark_weaver: thnks, and for the vector length, can I use stats info?
<mark_weaver>ah, to read the entire file: get-bytevector-all
<daviid``>mark_weaver: yes, a typelib file in this case
<mark_weaver>note that this returns a bytevector, which is not the same as a vector of integers
<daviid``>mark_weaver: working on this binding: g_typelib_new_from_memory (guint8 *memory, gsize len, GError **error);
<mark_weaver>if you need a normal scheme vectors of integers (which will take 4-8 times as much memory, depending on whether you're on 32-bit or 64-bit), then you could use 'bytevector->u8-list' and 'list->vector'
<mark_weaver>or write something more efficient to convert directly
<daviid``>mark_weaver: the CL implementation I'am using as a model seems to be happy with unsigned-byte 8
<mark_weaver>Baldtoenails: on the basis of the potential security issue I mentioned above, we might change the behavior of 'datum->syntax' when applied to syntax objects.
<daviid>here is what they do:
<daviid> (with-open-file (stream filename :element-type '(unsigned-byte 8))
<daviid> (let ((v (make-array (list (file-length stream)) :element-type '(unsigned-byte 8))))
<daviid> (read-sequence v stream)
<daviid> v)))
<daviid>
<Guest86396>mark_weaver: so I guess I can use get-bytevector-all
<mark_weaver>daviid: sounds good
<daviid>ok thanks.
<mark_weaver>np!
<cbaines>Can anyone help me with reading and writing records?
<cbaines>I have managed to write some data, and it comes out looking like #<<name> foo: "bar"> but trying to read it back in fails "Unknown # object: #\\<".
<cbaines>Do I need to do something with a custom printer to make it possible to read a record back in?
<janneke>cbaines: hash tables have a similar problem, i'm not sure why they are so poorly supported/integrated
<janneke>i have been using srfi-10 for hash tables but feel that's a kludge
<kristofer>cbaines, you mean like write the record to a file, and then read it back into the REPL from disk
<kristofer>?
<kristofer>I've been using gdbm to write records to disk
<kristofer>cbaines, https://github.com/NalaGinrut/guile-persist
<kristofer>that serializes records into sexp for storage in a file
<kristofer>I take that back, it converts hash tables into xml documents
<cbaines>Interesting... I was expecting this to be something that is better afforded by guile
<kristofer>cbaines, typically one would use an rdbms to store records and have some sort of sql mapper to map rows to scheme records
<kristofer>cbaines, you might also have a look at (guix graph) -- it uses the guix store to load profile packages as scheme records
<kristofer>guile has an db orm
<kristofer>I think with object db, it might be challenging to implement indexes
<cbaines>Arrgh, just getting confused between the literal? forms of records, and the evaluated form at the moment....
<cbaines>I've managed to write out some data which looks somewhat sensible
<cbaines>But the empty lists are written out as just (), and not '() as I would expect, and I think this is causing problems when I try and evaluate the data..
<random-nick>cbaines: well '() isn't an empty list, it's actually (quote ())
<cbaines>I get that
<cbaines>This is a simple example that I think represents the problem I am having: (primitive-eval `(1 2 3 ,(list)))
<cbaines>Or, maybe this makes more sense: (primitive-eval `(list 1 2 3 ,(list)))
<cbaines>Just evaluating (list 1 2 3 (list)) works fine, but quoting it, and the evaluating it does not work
<kristofer>eval-string?
<cbaines>I don't have a string to eval?
<cbaines>I have managed to write out something that looks ok (apart from maybe the () bits)
<cbaines>that is using the write function
<cbaines>I have then used read to load it back in
<cbaines>But evaluating it does not work
<cbaines>This is a simple standalone example of something that does not work http://paste.lisp.org/display/317043/raw
<cbaines>I am having difficulty in working out if its an implementation problem, or if I'm trying to do something that is not possible
<cbaines>The example works if data is changed to a number say, but not when its the empty list
***amz31 is now known as amz3`
<cbaines>I've actually managed to work around the above problem, just by avoiding outputting ()
<cbaines>but, I'm now having problems with eval
<cbaines>I'm trying to make the module explicit, but I am struggling to work out from the manual how I tell eval to use a specific guile module?
<amz3`>davexunit: do you strategies to debug parser using your parser combinators library
<cbaines>(found what I was looking for, resolve-module)
<spk121>ok. attempting to build guile 2.0.11 on cygwin. day #2
<galex-713>What is the “hash” computed by the “string-hash” function?
<galex-713>Although, if random is pseudorand, is there a way to get really random numbers? or to initialize to a really random number the random-state?
<spk121>the string hash in 2.0.11 is dead simple. foreach char: hash_val = hash_val * 37 + char
<galex-713>why * 37 ?
<galex-713>spk121: ^
<spk121>galex-713: don't know why 37 specifically, but the theory says that odd prime numbers are the way to go
<spk121>java uses 31
<galex-713>spk121: but what is this hash for?
<spk121>what is a string hash for in general? to check if two strings are different, you can check that each character in the strings are different. Or you can compare their hashes, which is faster.
<spk121>Since the hash numbers are just single integers instead of long lists of characters.
<galex-713>spk121: yeah but you have to go through all the characters of a string to compute the hash right?
<spk121>Yes. Thus, there use is usually constrained to strings that will have to be compared to other strings multiple times, such as in hash tables.
<galex-713>aaaah ok
<galex-713>spk121: but since the factor is 37, and you got more than 37 existing characters, you can find collisions this way right?
<spk121>galex-713: it is more complicated than that. Usually you don't need to worry too much until your integer hash value overflows. Sorry, I'm not a comp sci guy.
<galex-713>ok
<galex-713>spk121: I am sure I can find a collision
<spk121>If you use control characters, it is easy. The 1st print ascii is space = 20. 20*37 > 256, so there is less chance of collision for printable strings.
<spk121>but to be trivial (string-hash (string #\\null #\\a)) is the same as (string-hash "a")
<galex-713>yeah
<galex-713>spk121: so hashtables are for things where collisions aren’t a security problem you mean?
<spk121>sorry space is 32. haha
<galex-713>becaues otherwise why not use sha1/256/512
<galex-713>spk121: you got return which is 10
<spk121>string hashes are great for hash tables where the keys are short printable ascii strings.
<galex-713>oh I see
<galex-713>spk121: otherwise is it possible to make hashtables using anything else than this hash function? for exemple if you redefine string-hash to sha512 will hashtables work this way?
<spk121>galex-713: I guess so. I'm going to punt. Good luck.
<galex-713>So how do you get real random numbers in scheme?
<random-nick>as in use a seed based on current time?
<random-nick>well that isn't very random...
<mejja>you read /dev/urandom
<galex-713>mejja: no I mean /dev/random-like
<galex-713>there’s (platform-random-state) for that I think
<galex-713>random-nick: no, ^
<galex-713>sorry, (random-state-from-platform)
<lfam>It's interesting to me that the docs for (random-state-from-platform) say it's "appropriate for use in non-security-critical applications"
<lfam>Is there another procedure that is recommended over it?
<galex-713>I think “read from /dev/random”, but that’s in some way platform specific
<lfam>galex-713: That's what that procedure does. Maybe the fallback if /dev/urandom does not exist puts the whole procedure in the "not safe" category
<daviid>I've just used [twice in a raw] vector-length over a bytevector, by mistake, and instead of either complaining or what ever, it wants to display the content of the bv, which literally 'kills' my emacs, maybe it could do somthing better :)
<ijp>errors for me
<daviid>ijp: but does it print the content before to raise the error? I'm using 2.0.11
<ijp>it prints the content as part of the error
<ijp>ERROR: In procedure vector-length: Wrong type argument in position 1 (expecting vector): #vu8(1 2 3 4)
<daviid>ijp: right, I've just tested with a small. the problem is that it prints the all content, and the real bv is 62600 bytes
<daviid>ijp: so maybe it could prints the first few elements instead
<daviid>print*
<ijp>I'm sure there must be a general to truncate values in errors already, but I dont' know offhand
<daviid>ok, then it's too big, imo
<daviid>I mean the value to which it troncates, if it does, is too big: wrong type argument should only print 3, maybe 10 at the very most, imo
<daviid>now I fear to repl ask vector-length, this is truma :):)
<daviid>trauma*
<daviid>how do I get the adress of my bv, so I can paas it to glib?
<daviid>got it: bytevector->pointer