IRC channel logs

2016-03-07.log

back to list of logs

<rain1> https://www.gnu.org/software/guile/manual/html_node/SRFI_002d27.html#SRFI_002d27
<rain1>is this using strong randomness?
<rain1>I think it uses the same rng as normal guile
<rain1>I guess it's a compatability layer
<rain1>How do you use open rather than fopen from guile?
<zacts>hello guilers
<zacts>so is there a guile module that works with SICP, or can I use just plain guile?
<zacts>I know chicken scheme has this chicken egg (aka module)
<roelj>Is the 'with-directory-excursion' function part of Guile?
<taylan>roelj: nope, it's a macro in guix. defined in guix/build/utils.scm.
<roelj>taylan: Ah, thanks..
<thetan>Searching for solution to open pipe, take one line from it.
<thetan>how can I open standard input?
<jlicht>`current-input-port`, by default
<thetan>let me see
<taylan>thetan:
<taylan> (let* ((port (open-input-pipe "date --utc"))
<taylan> (str (read-line port)))
<taylan> (close-pipe port)
<taylan> str)
<taylan>⇒ "Mon Mar 11 20:10:44 UTC 2002"
<taylan>from the manual: (info "(guile) Pipes")
<taylan>you'll want to import (ice-9 popen) and (ice-9 rdelim) for that
<thetan>yes, I am reading the manual, but straight from manual is not working, it asks me for readline
<thetan>tried this: (open-file-input-port current-input-port ) but no go
<thetan>I am new, 2 days with Guile, converted 3 scripts from Perl yet.
<taylan>current-input-port is already an open port usually
<taylan>welcome :)
<taylan>e.g. (read-line current-input-port) will return a line from stdin as a string
<thetan>aha already open... let me see. Would be nice.
<taylan>if it says unbound variable 'read-line', then you have to (use-modules (ice-9 rdelim))
<thetan>taylan: I have put (use-modules (ice-9 rdelim)) in .guilerc, it seems it is not loaded when used like echo something | guile -c ""
<thetan>I got it working to read line with this: (read-line (current-input-port))
<taylan>thetan: .guilerc isn't read by scripts you run with guile; only when you start a guile REPL interactively.
<thetan>How can I get the output from system command into variable? (define whois (system (string-append "whois " ipnumber)))
<thetan>taylan: yes, I see now.
<taylan>like the snippet I pasted above, using open-input-pipe
<thetan>oh yes yes
<taylan>probably not as convenient as in Perl... :)
<taylan>there's SCSH for writing shell-script like things in Scheme, and I think there was a Guile port of it, don't know if maintained
<taylan> https://github.com/ChaosEternal/guile-scsh last commit here from 2 years ago, mentioning 2.0.11 which is the latest release...
<thetan>taylan: I find it sane rather, convenient is to me to use this kind of programing
<thetan>Trying to make it like this: (define port (open-input-pipe (string-append "whois " ipnumber)) (str (read-line port)) (close-pipe port) str)
<thetan>as like this is "unbound variable" (let* ((port (open-input-pipe (string-append "whois " ipnumber))) (str (read-line port))) (close-pipe port) str)
<thetan>open-input-pipe
<taylan>thetan: (use-modules (ice-9 popen))
<thetan>I got no errors now, but I need definition for let* to understand it. Because str is variables, only it gets nothing from system command.
<thetan>well maybe it works, let me see
<thetan>it works for "ls" not for "whois " ipnumber, hmm
<taylan>thetan: (let* ((var1 val1) (var2 val2)) ...) is like (let ((var1 val1)) (let ((var2 val2)) ...)), i.e. the expression 'val2' can reference 'var1'.
<taylan>contrast to (let ((foo "foo") (foobar (string-append foo "bar"))) foobar) which will say "error: unbound variable: foo" because the (string-append ...) is evaluated in an environment where neither foo nor bar are bound yet.
<thetan>aha
<thetan>taylan: ok I have made string-append, before let* it works, but I see I must do each time (define result "") to define variable, is that correct right way to do?
<thetan>where to paste code?
<lloda`> http://paste.lisp.org/ ?
<thetan>Here is my little problem: http://paste.lisp.org/display/309209#1
<taylan>thetan: 'let' forms are just to bind variables locally. here's an example of how this may be done: http://sprunge.us/OJVd
<taylan>(format #f ...) returns a string, (format #t ...) prints it to stdout instead
<thetan>locally, yes yes, so I shall rather use define?
<taylan>(and other valid values for the first argument to 'format' are ports)
<taylan>thetan: if you want to define a top-level variable, you have to use 'define'
<thetan>then the short snippet is not good example at all
<thetan>cannot move forward with learning.
<taylan>the snippet in the manual is for people who already know what 'let' does and just want to learn 'open-pipe'. it's a reference manual after all...
<taylan>maybe you want to go through a generic lisp/scheme tutorial first
<thetan>where is it
<taylan>don't know any off the top of my head. some good ones may be linked here: http://schemers.org/
<taylan>or if you're into the dry stuff you could also just read one of the standards, like R5RS
<taylan>but I'm guessing that would be too alien when not already familiar with lisp-family languages to some degree
<thetan>Now I know how Alice felt.
<taylan>:)
<thetan>It's OK, I understand that each (something) evaluates to something.
<thetan>I have used logo language before.
<taylan>I have a tiny lisp/scheme intro here, which might or might not be helpful: http://taylanub.github.io/doc/lisp-rundown.html
<taylan>it takes a strict bottom-up approach to teaching which may not be optimal
<thetan>very nice...
<thetan>what package or scheme/lisp shall I install to try those pairs out? Don't work in guile.
<rain1>hello
<taylan>thetan: they should work in Guile, except you'll have to wrap them in (quote ...) or '... because the Guile REPL expects sexprs that are Scheme code, not just any sexpr
<taylan>thetan: do you know XML Schema or JSON Schema? if so, think of it like: scheme code consists of sexprs that conform to a certain "S-Expression Schema" :)
<thetan>aha
<thetan>yes it works with '
<thetan>yes I know XML - and JSON, because I use it.
<thetan>S-Expression is pairs, and pairs may consist of pairs, am I right?
<taylan>yeah
<thetan>but ' is maybe just a list? No?
<thetan>'(first-element . (second-element . (third-element . NIL)))
<thetan>$6 = (first-element second-element third-element . NIL)
<taylan>lists are really made up of pairs
<taylan>the dotless notation is for convenience
<taylan>there's also vectors, which I think I don't mention in that intro. e.g. #(0 1 2 3) is a vector sexpr in Scheme, and contains no pairs. (foo . #(0 1 2)) is a pair whose right slot contains a vector, #(0 1 (foo . bar) 2) is a vector whose second element is a pair, etc.
<thetan>yes very nice, I am familiar with that concepts
<taylan>so it's not like pairs are literally the only data structure in sexprs, but vector syntax already differs between Scheme, CL, and Elisp...
<taylan>(i.e. these all have their own version of sexpr syntax, sadly. it's not standardized like JSON.)
<thetan>yes, that is for me now too steep to learn, I need just to learn let* correctly
<thetan>the runddown is clear short and nice.
<taylan>good to hear :)
<thetan>My way of thinking is like: (define result (let* ((port (open-input-pipe "ls")) (str (read-line port))) (close-pipe port) result))
<thetan>but I am missing foundation...
<thetan>bricks
<taylan>thetan: if you change 'str' to 'result' there, that should work
<taylan>or change the last 'result' to 'str'
<taylan>if you change the last 'result' to 'str' that will make the code clearer; otherwise there are two separate variables called 'result' in play there: one that 'define' is defining, and one bound locally by the 'let*'.
<thetan>(define result (let* ((port (open-input-pipe "ls")) (str (read-line port))) (close-pipe port) str))
<thetan>this one, does not give me result
<thetan>and I have feeling it could be simpler.
<thetan>like in Perl result = `ls`
<thetan>but I can make it of course, because in Guile there is anything to be made what one wish
<taylan>thetan: after executing that (define ...) form, the result will be bound to the variable 'result'. you can just type 'result' into the REPL and it will print its value.
<thetan>really...
<thetan>let me see
<thetan>(define result (let* ((port (open-input-pipe "ls")) (str (read-line port))) (close-pipe port) str))
<thetan>(result) Wrong type to apply: "findAbuseFromWhois.gle" <-- but I did not run it, I just wrote $ guile and it finds the script which I did not run
<thetan>will see messages later
<taylan>thetan: http://sprunge.us/QEWG here's an example of a syntax definition that makes it as easy as (define result (cmd->string "ls")) which is pretty similar to result = `ls` I'd say. :)
<taylan>thetan: type just 'result' without parentheses
<taylan>(result) will try to call the value of 'result' as a procedure. that fails since it contains a string and not a procedure.
<thetan>ha
<thetan>oh yes taylan
<thetan>taylan: do you have simple let* example?
<thetan>taylan: I still need to properly understand it by simplest example, this one is complex
<thetan>even though it works
<taylan>(let* ((foo "foo") (foobar (string-append foo "bar"))) <foobar is bound to "foobar" here>)
<thetan>taylan: too steep for me, isn't there more simpler thing?
<thetan>is it like (let* value is-this) ?
<thetan>because I think that assigns value to variables
<rain1>let* is pretty simple
<rain1>try this
<rain1> https://paste.debian.net/412824/
<rain1>it does assigns values to variables
<rain1>in another language its like: x = 10; y = x+200; z = y+3; return [x,y,z]
<thetan>OK basically (let* (here any number of variables or procedures) here output of one of those variables) ?
<rain1> http://www.schemers.org/Documents/Standards/R5RS/HTML/r5rs-Z-H-7.html#%_idx_128 here is the spec
<rain1>(let* <bindings> <body>)
<rain1><bindings> ::= ((<variable> <init>) ...)
<rain1>yes
<thetan>h yes, that brings clarity, thank you
<thetan>Trying to split the string: (set! result (string-split "OrgAbuseEmail: network-abuse@google.com" #\\ )), but not making it
<rain1>scheme@(guile-user)> (string-split "OrgAbuseEmail: network-abuse@google.com" #\\ )
<rain1>$1 = ("OrgAbuseEmail:" "network-abuse@google.com")
<rain1>it's splitting ok
<rain1>maybe the set! result part is wrong
<rain1>wouldy ou like to show more of the code? can use lisp paste or debian pastebin
<thetan>it is just that rain1
<thetan>yes, it splits directly. but with set! result becomes all of split parts of strings
<rain1>try with out set! result
<thetan>without yes, but I need to set variable
<rain1>you could use LET* ?
<rain1>like
<rain1>(let* ((result (string-split A B))) <body>)
<rain1>ill make an example
<thetan>let* is local, I need variable outside
<rain1> https://paste.debian.net/412847/
<thetan>or maybe I need to define result first as some list?
<thetan>let me see
<rain1>field is "OrgAbuseEmail", result is "network-abuse@google.com"
<thetan>sure it wors on your side, I see but that does not give me result
<rain1>result is there too
<rain1>you can use it inside the let
<thetan>and car result will not work, it has to be string-split, how do I know how many are inside
<rain1>sorry I don't understand
<thetan>can be: something email something
<thetan>I have to get string-split and later find email inside of parts of the list
<rain1>ahh..
<thetan>but that is not so important, I am learning, that is more important
<thetan>so I like to understand why (set! result (string-split "OrgAbuseEmail: network-abuse@google.com" #\\ )) is this not a list
<thetan>(display "OrgAbuseEmail:" "network-abuse@google.com") <-- this doesn't work for example
<thetan>(display result)
<thetan>this does but is one string
<thetan>my logic is, if string-split is split, result shall be split, but is not
<rain1> https://paste.debian.net/412848/
<rain1>maybe you could do it lik ethis
<thetan>let me see
<thetan>I see your point, only it does not assign or change variable, it is local: (display address) --> nothing
<thetan>do you know why it this: (set! result (string-split "OrgAbuseEmail: network-abuse@google.com" #\\ )) not giving 2 parts of the list?
<rain1>Can you show me the REPL session?
<rain1>or the whole code
<thetan>(define result "") before that, then: (set! result (string-split "OrgAbuseEmail: network-abuse@google.com" #\\ )) and (display result)
<thetan>that is all
<thetan>I don't learn whole code, I must learn string-split
<thetan>one by one
<thetan>rain1: thank you for helping me to learn
<rain1> https://paste.debian.net/412850/ this?
<thetan>exactly
<rain1>try using WRITE instead of DISPLAY
<rain1>then it will print the list as proper scheme code
<thetan>yes that works to show it
<thetan>do you know procedure to search for list element containing something and get it?
<rain1>did it resolve the puzzLe?
<thetan>ehm no
<thetan>I don't know if I get a list or not: (write (car result)) --> ("OrgAbuseEmail:" "network-abuse@google.com" "something")
<thetan>so I get first part of pair that all, and cdr is nothing
<thetan>I was thinking string-split gives me list, but it looks like it simply gives me what? string back but split , but is still string
<thetan>ok it is list, but if I assign it to variable, it is not any more, apparently
<rain1>let's try!
<thetan>I think it does work
<rain1>scheme@(guile-user)> (string-split "foo bar" #\\ )
<rain1>$1 = ("foo" "bar")
<rain1>scheme@(guile-user)> (string-split "foo bar baz quux" #\\ )
<rain1>$2 = ("foo" "bar" "baz" "quux")
<thetan>(define new "")
<thetan>(set! new (string-split "OrgAbuseEmail: network-abuse@google.com something" #\\ ))
<thetan>(display (car new))(newline)
<rain1>so the list can be any length
<thetan>So this does work, it is list
<thetan>I got it, maybe I was absent with my mind
<rain1>yeah!
<thetan>later when I buy some speck for my wife I will be back...
<rain1>havea nice time!
<rain1>you can also (list-ref <list> <index>)
<rain1>to get the other elements
<paroneayea>hello!
<rain1>hiya
<thetan>rain1: nice to know about list-ref
<thetan> is there something list list-match?
<thetan>to find certain element containing @ for example, instead of iterating over list..
<rain1>srfi-1 has most extra list functions
<rain1>FIND can do this http://srfi.schemers.org/srfi-1/srfi-1.html#find
<rain1>but you have to pass in a predicate that checks if a string has @
<rain1>string-contains could work https://www.gnu.org/software/guile/manual/html_node/String-Searching.html
<rain1>(define (contains-@ str) (string-contains str "@"))
<rain1>(find contains-@ (string-split ...))
<rain1>something like that could do it,
<rain1>after you (use-modules (srfi srfi-1))
<thetan>string searching is ok thank you, only it does not look like list searching
<thetan>maybe find is for that
<rain1>I showed how to build a special function for use with FIND
<thetan>aha yes yes, thank you, trying this out
<rain1>ill post an eaxmple
<thetan>(find contains-@ new)
<thetan>$3 = "network-abuse@google.com"
<thetan>very nice, it works
<rain1>:D
<thetan>my problems is bigger and bigger, how to remember where is what? Some definitions are in srfi, some in guile, etc. too many
<rain1>just search through the modules
<rain1>to find what you need
<rain1> https://www.gnu.org/software/guile/manual/html_node/Guile-Modules.html#Guile-Modules
<rain1> https://www.gnu.org/software/guile/manual/html_node/SRFI-Support.html#SRFI-Support
<rain1>these are the main lists
<thetan>rain1: now when I get result with double quots " ", why is that? How do I remove it?
<thetan>aha with display is without quotes
<thetan> http://paste.lisp.org/display/309232 it works, it can find now email address. Now I can put it as action to clipit
<rain1>nice one :)
<thetan>spam was waiting so long...
<thetan>Oh I need to feed it to clipit... not just action
***guile-guest5 is now known as edw
<edw>I've noticed (in 2.0.11) that a SRFI 69 hash is not a built-in hash, so things like `alist->hash-table` 1) require importing SRFI 69 and 2) generate values that the built-in procs don't recognize. Is there a recommended way to smooth over these issues?
<edw>And of course there are R6RS hash tables…
<thetan>somebody knows what is preferred database to be used in GNU software? Which one shall I use from Guile?
<thetan>AndI will have 500,000 - 1 million records, contacts, emails, such inside.
<daviid>thetan: it depends on so many criteria, but to make it short: if you don't need a client/server db, you could use sqlite, otherwise I'd use postgres, guile has bindings for both. guile-pg, the postgres bindings, is far more advanced then the sqlite3 bindings, if that matters to you
<daviid>have to go afk, bbl
<thetan>daviid: yes, I already use postgresql, yes. I was thinking maybe there is something preferred, or faster
<thetan>daviid: not that I use postgresql in Guile, but I want to convert to Guile
<edw>thetan: these days 0.5-1.0e6 records isn't an unreasonable amount of data to store in memory. Pg may be overkill.
<thetan>edw: Guile is capable of storing much in memory?
<thetan>yes, I also need some data base to store stuff inside.
<edw>theta: Do the math: If every object is 1K, and you want a million of them, that's 1GB. Not an unreasonable amount of memory.
<edw>Whether you're using Sqlite or just naked Guile, space will be used by housekeeping data, of course.
<thetan>thanks. When you say "naked guile" is there any native, built-in guile database?
<thetan>OK I understand the memory, and this. Only asking separate, maybe there is something.
<thetan>learning..
<kristofer>hello!
<edw>thetan: A list or a vector or a hash table or any composite type is a database. You should think about what you're trying to accomplish and choose a solution -- Pg, Sqlite, bespoke in-memory data with (de)serialization -- accordingly.
<thetan>Thank you. edw: is vector or hash table stored in file?
<rain1> https://www.gnu.org/software/guile/manual/html_node/Soft-Ports.html
<rain1>I don't understand thunk for flushing output
<rain1>what is that exactly? how would you test it
<thetan> https://duckduckgo.com/html?q=thunk&t=gnu
<edw>thetan: I'm not familiar with Guile's abilities with respect to serializing hash tables. Anything can be stored to a file; worst case you'd need to write a proc to walk the data structure and dump the values. And then write another proc to eead them back in, obviously.
<rain1>What should the function do that is passed in as the third vector element of make-soft-port?
<rain1>my best guess would be emit a single char each call until you finish, then eof-object - can anyone who knows a bit about ports etc. confirm?