<euandreh>How do I read the content of a file as a string? I did (call-with-input-file "f" read), but I get a symbol instead <spk121>euandreh: one way is to use read-delimited, but, then to have an empty string for the 'delim' parameter <spk121>read-delimited is in (ice-9 rdelim) <spk121>(read-delimited "" (open-input-file "filename.txt")) <daviid>euandreh: there is also (use-modules (ice-9 textual-ports))- then get-string-all input-port ... <justin_smith>euandreh: the "read" function is the "R" in repl, its job is to turn input streams into symbols and lists and numbers ***oni_on_ion is now known as oni-on-ion
***sneek_ is now known as sneek
***wxie1 is now known as wxie
***apteryx_ is now known as apteryx
<sneek>elliotpotts, you have 2 messages! <sneek>elliotpotts, leoprikler says: have a look at scm_c_define_gsubr and perhaps pointer->procedure <sneek>elliotpotts, leoprikler says: ah you're already using define_gsubr. You probably want to write your bind helper in a module like so (define (bind1 fn arg) (lambda args (apply fn arg args))), then refer to it from C++ using module-ref et al. Having a look at pointer->procedure would probably still be helpful tho, especially if you can resolve argument types at compile time <euandreh>I'll go with daviid solution, and use (call-with-input-file "f" get-string-all) <ArneBab>manumanumanu: wow, nice! (in-file "…") with auto-closing is cool! <ArneBab>manumanumanu: can it also process files line-by-line? <manumanumanu>ArneBab: sure. (in-file "path" [reader [eof?]]) where reader is a unary procedure that is passed a port (defaults to reach-char) and eof? defaults to eof-object? <manumanumanu>I could even wrap it in dynamic-wind to close the port on a non-local exit <manumanumanu>I believe guile-fibers could potentially suspend the thread there, for example <manumanumanu>wingo: sorry to bother you, but I was wondering about how guile hoists variables out of loops: Would a (if (= (vector-length vec) index) ... benefit by having the vector length moved out of the loop body, or is that done automagically? <leoprikler>in both cases the loop was completely unrolled (for a statically known vector of length 3) <leoprikler>I assume Guile will optimize for you when it can reason about the length of the vector. <manumanumanu>leoprikler: that is just peval and inlining, which is not the same thing <manumanumanu>I want to know whether (vector-length v) is called at every loop, or if the call is hoisted <leoprikler>Obviously the semantics differ if you have a procedure, that could potentially mutate the vector. <leoprikler>But assuming you don't, the call is likely hoisted <manumanumanu>The call is definitely hoised in this case. the person writing the code can't access the underlying variable holding the vector. <manumanumanu>(in-vector ...) gives the vector a temporary name for that reason. The loop shouldn't fail because the user mutates the original binding <manumanumanu>(this is part of my endeavour to create the love-child of racket's for loops and Alex Shinn's foof-loop. <leoprikler>well, assuming the vector comes from outside and you call an arbitrary proc (in-vector), that may not always hold, but should hold most of the time <leoprikler>[of course you can also copy the vector, then it will hold all of the time] <leoprikler>My implementation of vector-looping, that assumes it can change: oof-loop. <manumanumanu>leoprikler: the reason it's called goof loop is because I goofed in the issue tracker of chibi scheme believing I understood the iterator protocol when I obviously didn't :D <leoprikler>I thought it was goof loop because goof follows foof [g follows f] <leoprikler>Which of course presupposes the existence of doof-loop :) <leoprikler>the next logical steps would of course be hoof-loop, loof-loop and poof-loop <leoprikler>though poof-loop has the nasty tendency of sometimes swallowing your data <manumanumanu>The thing is... I'm done. Now I'm just writing docs, and polishing the implementation. The only thing I have left is to ensure that the body is executed at least once. ie: (loop () 1) => 1 and (loop/list () 1) => (1). Currently I believe it either returns unspecified or loops forever. <leoprikler>well, time to write hoof-loop, which loops forever *and* returns unspecified <lampilelo>so i hope my body won't get executed, not even once <ArneBab>If you die in sleep, you likely got terminated :-) <lampilelo>maybe i just hibernated and didn't really die? <leoprikler>my personal intuition would be to not execute anything for empty input either and just return *unspecified* too