IRC channel logs

2015-09-15.log

back to list of logs

<paroneayea>daviid: yeah
<mark_weaver>paroneayea, davexunit: kristofer asked: "I need to get every <strong> node from an html document. I'm having trouble figuring out the best approach. Can someone point me to a good document?"
<mark_weaver>can either of you help him?
<mark_weaver>(I could try, but this is more your area of expertise)
<paroneayea>mark_weaver: kristofer: hm... well... if it were xhtml it would be easier. I don't think guile currently has tools that can process the soup we call html
<paroneayea>but
<paroneayea>if I were going to look into processing html soup, I might look into how python's lxml does it
<paroneayea>but sadly it's a complex process..
<mark_weaver>well, there exists something called "htmlprag" that parses html into sxml iirc
<paroneayea>ooh! I hadn't heard of it
<paroneayea>oh neat in guile-lib
<davexunit>well is this scraping or do we have well-formed html?
<paroneayea>kristofer: once you got it into sxml you might want to try using sxpath
<paroneayea>I haven't tried it, but if this were elsewhere I'd do xpath to pull things out, assuming you just wanted to quick-extract something from the DOM tree
<mark_weaver>I wasn't sure if sxpath can do this or not. sxpath really needs better documentation.
<paroneayea>let's see, I have some fresh sxml right here I was working with
<paroneayea>mark_weaver: let me give it a try :)
<mark_weaver>if wouldn't be hard to write a little procedure to search the tree for 'strong' nodes, but if sxpath can do it nicely, that would be ideal.
<paroneayea>scheme@(guile-user)> ((sxpath `(// tr td)) test-sxml)
<paroneayea>$8 = ((td "blue") (td "2") (td ("sad")) (td "2") (td "boops") (td "2") (td "") (td "2") (td "purple") (td "2") (td "on") (td "2"))
<paroneayea>so there, I searched for all <tr><td>(whatever foo here)</td></tr elements
<paroneayea>pulling out all the tds
<paroneayea>kristofer: http://wiki.call-cc.org/eggref/4/sxpath has good docs
<paroneayea>and http://metapaper.net/query/examples/ may also help, search around the web for xpath tutorials if need be
<paroneayea>kristofer: so in your case
<paroneayea>(match ((sxpath `(// strong)) your-sxml-here) (((_ strong-texts) ...) strong-texts))
<paroneayea>if you put your-sxml-here
<paroneayea>that'll pull out all the text elements
<paroneayea>or even better
<paroneayea>(match ((sxpath `(// strong)) your-sxml-here) (((_ (? string? strong-texts)) ...) strong-texts))
<mark_weaver>thanks paroneayea!
<paroneayea>oh that last one actually might break if not all things are strings
<mark_weaver>kristofer: and you can use 'html->sxml' from htmlprag (in guile-lib) to parse the html into sxml.
<paroneayea>there are other ways to write this, but lazily:
<paroneayea>(remove (lambda (x) (not (string? x))) (match ((sxpath `(// td)) test-sxml) (((_ strong-texts) ...) strong-texts)))
<paroneayea>that'll ignore anything that's like <strong><i>foo</i></strong>
<paroneayea>in case you don't want to deal with the annoyingness of finding the strings inside there
<paroneayea>and it doesn't matter enough
<paroneayea>but probably, start with the first version I gave you :)
<mark_weaver>it depends whether kristofer wants strong nodes that contain other tags
<paroneayea>yes
<paroneayea>(use-modules (ice-9 match) (sxml xpath))
<paroneayea>you could even map an xpath over your xpath results to pull out the strings, but maybe we shouldn't go there for now ;)
<paroneayea>kristofer: sorry if that was a bit overwhelming of a response
<paroneayea>hopefully helpful?
<kristofer>paroneayea, mark_weaver you guys rock! very helpful
<kristofer>in the repl, http-get returns the header in $1 and the body as a string in $2. how can I use the string response $2 in function?
<mark_weaver>kristofer: one way is to (use-modules (ice-9 receive)) and then write something like (receive (header body) (http-get ...) <code that refers to 'header' and 'body')
<mark_weaver>see secion 6.13.7 (Returning and Accepting Multiple Values) in the guile manual
<mark_weaver>another way is to (use-modules (srfi srfi-11)) and then (let-values (((header body) (http-get ...))) <code>)
<kristofer>mark_weaver, sweet thank you for your help.
<mark_weaver>np!
***Shozan is now known as SHODAN
<civodul>Hello Guilers!
<csed>Hello.
<csed>So wait. () in Scheme isn't a thing?
<csed>In Lisp () is the equivalent of an empty list, or nil, right? So how'd you represent an empty list? Just nil?
<artyom-poptsov>csed: Hi. An empty list is just '()
<ecraven>csed: the unquoted form () is an error in Scheme
<csed>ecraven, artyom-poptsov: Huh, right. What about nil, then? I mean, nil is still the cdr of last, right?
<remi`bd>in Guile, there’s a difference between false and nil
<remi`bd>nil is represented by the empty list '()
<remi`bd>false by the value #f
<artyom-poptsov>So the cdr of the last element of a list will return an empty list, or '()
<remi`bd>and (if '() 'foo 'bar) => 'foo
<remi`bd>while in common lisp, (if '() 'foo 'bar) => 'bar
<csed>remi`bd: Is this Guile, or Scheme specific?
<ecraven>csed: no, Scheme doesn't have the symbol nil bound to anything by default
<ecraven>what you call nil in other lisps is '() in Scheme
<artyom-poptsov>csed: You can think of Scheme list as a chain of pairs, each of which has an element of a list as the car and a reference to the next pair as the cdr. The last pair of a list (last pair in the chain) has '() as the second element.
<artyom-poptsov>s/as the second element/as the cdr/
<csed>artyom-poptsov: Right. So like Lisp, only () isn't the same as nil. And nil isn't even bound to anything by default. Alright, that makes sense.
<csed>And an empty list isn't false, which I find a bit confusing.
<nalaginrut>In Scheme, only #f means False, any other object means True, In conditional tests, all values count as true except for #f
<artyom-poptsov>I think '#nil' is bound in Scheme, for compatibility reasons with ELisp: https://www.gnu.org/software/guile/manual/html_node/Nil.html#Nil
<csed>Alright, well. Interesting.
<civodul>#nil is never used in pure Scheme code
<civodul>it's only meant to be used in Guile-Emacs
<artyom-poptsov>csed: Besides, you can check expressions in your REPL, when in doubt.
<lloda>literals are printed without quotes and that can be confusing for beginners, I think, that there's such a thing as 'read syntax'
<csed>artyom-poptsov: That's how I got to the question in the first place. I tried something like (eq? () nil), and expected it to work.
<csed>So, concerning Guile listening on port X. Any standard ways of securing this? Port knocking is one idea, but it'd be nice if you could set up some sort of auth as well.
<davexunit>like a REPL server? those aren't meant for public access.
<davexunit>or rather access outside the local machine
<csed>davexunit: Sure. But it's possible, right? In that case, some sort of security wrapper would be pretty swell.
<artyom-poptsov>csed: You can access a REPL server remotely using SSH port forwarding... or by means of Guile-SSH :-)
<davexunit>yeah ssh would be the way to go
<taylanub>see the -L and -R options of ssh for some easy port forwarding
<csed>taylanub: Yeah, SSH tunneling would work as well.
<csed>artyom-poptsov: Looks interesting. I'll check it out.
<csed>Alright, cheers. I'll mess around with this until I figure out something that works.
<kristofer> http://paste.lisp.org/display/155232
<kristofer>I need some help using map with string-append. I'd like to put a ":" in between the strings
<taylanub>kristofer: you can use string-join instead
<kristofer>I'd guess there's a way sxpath can do it, but I haven't figured it out
<taylanub>like (map (lambda strings (string-join strings ":")) string-list-1 string-list-2 ...)
<kristofer>taylanub, success! thank you
<taylanub>hth :)
<lloda>(use-modules (ice-9 format)) (format #f "~{~a~^:~}" list-of-strings)
<remi`bd>hum
<remi`bd>in guile, there are functions names cos, sin, and tan that are not well documented
<remi`bd>for instance, the documentation for `cos z` is: “Return the cosine of Z.”
<remi`bd>it should be precised that Z is a value in radians
<davexunit>what else is there to document?
<mark_weaver>hmm
<remi`bd>oh, and what is the usual way to work with this functions?
<remi`bd>is there a PI constant or something?
<davexunit>no pi constant.
<remi`bd>(searching for “pi” in the documentation is unsucessful)
<mark_weaver>radians is used all in all real work with math. in math at least, degrees are only used in early education
<mark_weaver>remi`bd: (acos -1) will give you pi
<remi`bd>:D
<davexunit>oh yeah! thanks for that nice tip mark_weaver
<davexunit>I'll adjust my 'pi' definition in Sly
<remi`bd>Scribus, for instance, uses degrees
<remi`bd>thanks!
<mark_weaver>sure, degrees are still used to specify angles in non-mathematical work
<davexunit>I wrote little {cos,sin,tan}-degrees procedures for cases where I want to use degrees
<mark_weaver>I see that neither R5RS nor R6RS contain the word "radian" anywhere in them. I guess they thought it went without saying :)
<mark_weaver>but, the glibc docs mention that radians are used
<mark_weaver>I wonder which programming languages, if any, use degrees for their trigonometric functions.
<mark_weaver>when you learn the calculus, it becomes clear why radians are the natural units for trigonometric functions
<lloda>saying that x in cos(x) is radians is like saying that x in exp(x) is in nepers :p
<kristofer>I'm trying to drop the first 13 chars from each element in the list of strings
<kristofer> http://paste.lisp.org/display/155235
<mark_weaver>if you use radians, then the derivative of sin(x) with respect to x is cos(x), and the derivative of cos(x) is -sin(x)
<mark_weaver>if you use degrees, then those derivatives have pi/180 constants sprinkled around
<holomorph>it shouldn't be hard to find out if one's trig functions are using radians or degrees
<davexunit>it's all about that unit circle
<mark_weaver>and then there's the fact that e^(i*x) = cos(x) + i*sin(x)
<mark_weaver>but if you use degrees, then again the pi/180 constant has to be introduced
<lloda>holomorph: there can be confusion sometimes, as in any conversion, e.g. with small angles
<mark_weaver>and of course, for small x, sin(x) ~= x, but only if you use radians
<lloda>my rule is to never ever have anything in degrees unless the variable name is named xxx-deg or (deg number-in-degrees) for literals
<lloda>mark_weaver: that's true for small angles whatever unit you use, since radians<->degrees is a linear map
<mark_weaver>lloda: I think you're mistaken
<mark_weaver>try it
<lloda>ah, no, you're right
<lloda>brainfart :p
<mark_weaver>:)
<mark_weaver>kristofer: (map (cut string-drop <> 13) <list-of-strings>)
<mark_weaver>'cut' is defined in (srfi srfi-26)
<mark_weaver>(cut string-drop <> 13) is a shorthand for (lambda (s) (string-drop s 13))
<kristofer>mark_weaver, thanks.
<kristofer>I just started learning scheme, I appreciate everyones help
<mark_weaver>glad to help! happy hacking :)
<paroneayea>hi everyone!
<zacts>hi guilers
<amz3>héllo :)
<paroneayea>davexunit: you've probably already read but http://www.more-magic.net/posts/lispy-dsl-scss.html
<davexunit>paroneayea: it's been awhile but yes I saw that
<davexunit>I want such a thing
<davexunit>most of all I want a sexp -> OpenGL GLSL shader converter
<davexunit>that may be the next s-acronym language I tackle
<paroneayea>hm
<paroneayea>sxml seems rock solid in most ways
<paroneayea>though the mention that sxml does not support namespaces in current implementations probably is maybe something to address http://www.more-magic.net/posts/lispy-dsl-sxml.html
<civodul>what if we bootstrapped Guile from Make instead of C? https://github.com/shinh/makelisp
<davexunit>hehehe
<daviid>In Guile We Trust! :)
<davexunit>ACTION starts 'guild init'
<davexunit>guild is very easy to extend, just like guix subcommands.
<daviid>clojure is hell! man they depend on external rubish things like maven, leiningen, you just can't simply load a friend module written in java neither simply load a jar and use it, it is terrible
<daviid>and yet another tool chain, which is 10 inferior to the autotool chain...
<daviid>why on earth humans ever invented java ? that is the quizz :)
<daviid>ACTION wanted to implement guild init, but he's in hell for now :) 
<davexunit>that's why I don't want to do much with Clojure
<davexunit>daviid: I could hand it off to you still, or I could make a repo in my git server that we can both hack on
<daviid>davexunit: the problem is the research lab i'm working for extensively use and progam digital image processing, and unfortunately, along the years, no C library survived, and imagej became one of the mostly used
<davexunit>ACTION sees the new mailing list thread about new logo and website
<davexunit>woooow
<daviid>davexunit: yes, adding to your git host is a good idea
<daviid>i'd be happy to contribute has time allows
<davexunit>daviid: there's plenty of good software written in Java... I just don't want to write it or keep it running :)
<davexunit>daviid: great! I'll get it up online when I can. please send your ssh public key to davet@gnu.org so I can give you commit access.
<daviid>davexunit: exactly! i really am frustrated :) when i have to deal with these... and clojure people are not so nice as guilers! they ar even agressive from time to time
<daviid>davexunit: will do, tx
<davexunit>I maintain the opinion that Clojure is a compromised Lisp.
<davexunit>it looks like Lisp at first glance, but it's missing important things.
<daviid>davexunit: the big big problem is very quickly you need to know java and as I said it is a real nightmare to load [you just can't actualy] other modules, unless you start to know maven and leiningen: this is a sort of dictature to me
<daviid>why should I have to learn anything else then emacs, a clojure inferior mode and clojure ? the design is wrong imo
<daviid>and immutable, but you can quickly do what ever you want usig java, so it's a lie
<daviid>we can also do immutable in guile, and as i said earlier, goops, it is a mater of discipline
<daviid>and necessity [i don't beleive in all immutable]
<davexunit>Clojure has some real nice inside of it, but I don't want the rest of it.
<daviid>ok ok, that was the minute of complains haha let's get things done
<davexunit>Guile website redesign mock up: https://multimedialib.files.wordpress.com/2015/09/website-mockup-2015-09-15.png
<davexunit>from the mailing list
<holomorph>guile's website is just fine :)
<davexunit>overall I love it.
<daviid>great! I overall like it as well
<paroneayea>omg
<paroneayea>that guile website redesign looks great
<paroneayea>amazing ;_;
<paroneayea>ACTION excited
<daviid>it's really cool. Later will read it carefully and if i feel i should provide some feedback...
***dje is now known as xdje
<thorwil>quite a lot to like about that mockup. the logo at the top is weak and shaky, though
<daviid>thorwil: oh, i did like it actually
<thorwil>i mean, there's almost a circle, but the geometry seems slightly off