IRC channel logs

2023-10-04.log

back to list of logs

<abcdw>sneek: later tell graywolf I found this implementation of srfi-197 somewhere and it works fine in guile: https://git.sr.ht/~abcdw/guile-nrepl/tree/5df19ee775a9297be138d52e94170c7ed2286d02/src/srfi/srfi-197.scm#L1
<sneek>Got it.
<ekaitz>hi! can I evaluate guile code in an empty environment that only contains a set of functions defined by me?
<ekaitz>oh... #:pure?
<ekaitz>but can I create a module and send it to eval?
<flatwhatson>ekaitz: maybe local-eval is what you need? https://www.gnu.org/software/guile/manual/html_node/Local-Evaluation.html
<ekaitz>flatwhatson: exactly, that's what i need! good catch!
<ekaitz>thank you
<ekaitz>flatwhatson: oh but this doesn't let me create an environment myself, only capture the one I currently have
<flatwhatson>yeah, i guess you'll need to create that environment and then capture it!
<ekaitz>but how do I forget stuff like call-with-input-file?
<ekaitz>maybe create a #:pure module and return the-environment of it?
<ekaitz>hm!
<ekaitz>i could also use a sandbox but I think that might be too much for this case
<rlb>haugh: along similar lines, there's as-> in clj https://clojure.github.io/clojure/clojure.core-api.html#clojure.core/as-%3E and looke has a guile version https://codeberg.org/lokke/lokke/src/branch/main/mod/lokke/base/syntax.scm#L727-L734
<flatwhatson>ekaitz: hmm, probably eval-in-sandbox is the right tool here?
<ekaitz>yeah...because #:pure doesn't let me do anything
<ekaitz>not even quote or anything
<flatwhatson>seems like the sandbox module stuff is just sugar over first-class modules
<flatwhatson>so you could (let ((m (make-module))) (module-add! m
<flatwhatson>er...
<flatwhatson>(module-define! m 'frobnicate (lambda () ...))
<flatwhatson>(eval-in-sandbox expr #:module m)
<ekaitz>flatwhatson: OH i spent a lot of time looking for modules like those but I couldn't find
<ekaitz>thank you, this is what I actually need
<ekaitz>I think
<ekaitz>haha
<ekaitz>local-eval in contrast doesn't let me (define ...)
<ekaitz>so just eval
<ekaitz>and I can generate a #:pure module if I want for it
<ekaitz>still cannot `define` in eval?
<ekaitz>:(
<ekaitz>solved with load
<ekaitz>in SXML how do I make it not add entities like &amp; ?
<ekaitz>and use a & instead
<ekaitz>I'm talking about this for example:
<ekaitz>(sxml->xml (xml->sxml "<t>\"HELLO\"</t>"))
<ekaitz><t>&quot;HELLO&quot;</t>
<ekaitz>I talked about this the other day with RhodiumToad i think, but i didn't realize of this case
<efraim>I'm looking through the manual, it looks like string-index and string-skip are the same
<mirai>ekaitz: some characters have to be escaped
<mirai>things like >, < and & have to be escaped if they're not within a CDATA section
<mirai>the double-quote doesn't have to be escaped if its character data (i.e. <foo>"hi"</foo> is ok) but it does for attribute values depending on whether you used a single or double quote for opening
<mirai>but <t>&quot;HELLO&quot;</t> should mean the same thing as <t>"HELLO"</t>
<mirai>see this answer <https://stackoverflow.com/a/1091953>
<ekaitz>mirai: and if i'm trying to output some html...? javascript doesn't need that kind of scaping
<mirai>the disappointing answer is: XML ≠ HTML
<ekaitz>haha mirai yeah, but sxml should work with html too
<ekaitz>shouldn't it?
<mirai>and HTML5 isn't SGML (au contraire de HTML4)
<mirai>ekaitz: not really
<mirai>it “can” in some cases
<mirai>but there are certain HTML things that are illegal in XML
<mirai>I should mention that there's XHTML and XHTML5
<ekaitz>yup
<mirai>which is HTML but with valid XML syntax
<ekaitz>should I take a look to them and generate XHMTL5?
<mirai>yes
<ekaitz>> In 2012 at the moment of writing, it was clear that W3C decided to abandon XHTML for HTML 5.
<mirai>if you go with the XHTM* way then you should be able to use the standard XML tools
<ekaitz>oh no
<mirai>they did?
<ekaitz>let me read further just in case
<mirai>where are you reading this?
<ekaitz>it was a random stackoverflow answer but now I'm reading the html standard https://html.spec.whatwg.org/
<mirai> https://html.spec.whatwg.org/multipage/xhtml.html
<mirai>> The XML syntax for HTML was formerly referred to as "XHTML", but this specification does not use that term (among other reasons, because no such term is used for the HTML syntaxes of MathML and SVG).
<ekaitz>ooh i see
<ekaitz>i found how they do javascript
<ekaitz>and it's inside a CDATA thingie
<ekaitz>not that bad after all
<ekaitz>but i can't generate a CDATA block with sxml either, can I?
<mirai>no idea. Guile's SXML docs aren't too good here
<ekaitz>:(
<mwette>I think you can. Why not write xml w/ CDATA and send through xml->sxml
<mwette>I think it might be something like (*CDSECT* "string")
<mwette>Also, you could convert &<; to < by post-processing the sxml tree, looking for strings and send them through a simple state machine to convert.
<mwette>Just tried. "<x><![CDATA[\"hello\"]]></x>" ==xml->sxml==> (*TOP* (x "hello"))
<mwette>Sorry, s/"hello"/"\"hello\""/
<RhodiumToad>sxml->xml has no way to write cdata sections
<RhodiumToad>xml->sxml can _read_ cdata sections, but guile doesn't include the upstream bug fix to read them correctly, so it corrupts them in some cases
<RhodiumToad>you can generate arbitrary output inside sxml->xml output by putting procedures (or applicable objects) into the sxml tree
<RhodiumToad>I have a proof-of-concept example to output cdata that way if anyone is interested
<ekaitz>(sxml->xml (lambda () "hola \"")) => "hola \""
<ekaitz>RhodiumToad: thank you!
<ekaitz>this is what I wanted!
<ekaitz>does the manual mention this? i've been searchin like crazy...
<RhodiumToad>yes
<RhodiumToad>oh wait, maybe it doesn't
<ekaitz>we should add it then
<ekaitz>RhodiumToad: but if I put the lambda inside some structure it disappears...?
<RhodiumToad>what sort of structure?
<ekaitz>a list
<ekaitz>(sxml->xml (text ,(lambda () "\"")))
<ekaitz>it returns <text></text>
<RhodiumToad>the lambda shouls output to the current output port, not return a string
<ekaitz>oh ok
<ekaitz>RhodiumToad: great! working!! thanks a lot!
<RhodiumToad>(sxml->xml `(foo (bar (baz ,(lambda () (display "<![CDATA[foo<>bar]]>"))))))
<ekaitz>yeah! I managed to do it :) thanks again
<RhodiumToad> https://dpaste.org/YdCwb <-- a goops approach for an object that prints itself as cdata
<RhodiumToad>complete with demented-fish-escape code
<ArneBab>mbakke: I did not try representing G-expressions yet. What I do for other quoted expressions is to just prefix the line with `. So maybe use ~ as ~(...)?
<lilyp>xhtml5 is weird
<lilyp>on the one hand, you can use javascript to do whatever, on the other it's like "namespaces? what are namespaces?"
<lilyp>which gets annoying if you want to do inline svg, mathml and rdf for no particular reason
<lilyp>(especially rdf)
<haugh>rlb, as-> makes a lot of sense in clojure, where the multi-value considerations can be neatly handled with all the data-oriented destructuring
<haugh>maybe it composes well with the other stuff in (lokke syntax); are there docs?
<haugh>honestly my only gripe with `chain' is reordering values