Re: [racket-users] Re: Andy Wingo's fold

2020-06-25 Thread Neil Van Dyke
Catonano, I haven't yet studied that paper of Andy Wingo's (thank you 
for mentioning it), but a couple ideas for answering your questions...


If people in Guile are using that tree fold approach, you might ask 
about it on one of the Guile email lists.  Incidentally, Andy has long 
been a member of the community around Guile, as well as of the Scheme 
community in general.


If you want to use that tree fold approach in Racket afterwards, most 
Scheme code will still work in Racket.  And you could probably port or 
repackage most Guile utility libraries.  (The main tricky part that 
comes to mind, in porting RnRS Scheme code to Racket, is if the code 
uses mutable pairs.)


Another option to keep in mind is that, normally when you read an 
academic paper, once you've given it a close read, and made an effort to 
be reasonably conversant in at least one aspect of the background 
material, IMHO, it's perfectly proper to contact the author of the paper 
directly, with good comments/questions.  They might not be able to keep 
up with their email, nor always sort it perfectly, but reaching out 
about a paper is part of scholarly culture, so don't be too shy.


FWIW, here's another example of tree folding, which I did as an exercise 
while trying to understand some of Oleg Kiselyov's XML work better: 
https://www.neilvandyke.org/racket/json-parsing/  (If it doesn't 
immediately help at all, don't waste your time looking at it any more.  
I'd do the interface differently next time, and definitely not use 
`syntax-rules` in the implementation again, but it's an example.)


Neil

--
You received this message because you are subscribed to the Google Groups "Racket 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/da82b74d-eb8f-e76b-e730-db98e3c56999%40neilvandyke.org.


Re: [racket-users] Re: Andy Wingo's fold

2020-06-25 Thread Philip McGrath
On Sun, Jun 14, 2020 at 2:20 PM Catonano  wrote:

> I'm referring to a paper titled: "A better XML parser through functional
> programming"
>
> by Oleg Kiselyov
>

Ah, I see. I'm not deeply familiar with it myself (I mostly use Racket's
`xml` library), but there is a Racket port of Oleg's SSAX, and the source
code includes extensive comments.

Code: https://github.com/jbclements/sxml
Package documentation (limited): https://docs.racket-lang.org/sxml/

Oleg's website also has some links, though some are broken:
http://okmij.org/ftp/Scheme/xml.html#XML-parser

Hope this helps!

-Philip

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAH3z3gYHHJ7NHr4%3DNmUBOWHEU6skgBYac3n78OVHn%2BVuB%3D74YQ%40mail.gmail.com.


Re: [racket-users] Re: Andy Wingo's fold

2020-06-14 Thread Catonano
Il giorno ven 12 giu 2020 alle ore 10:57 Philip McGrath <
phi...@philipmcgrath.com> ha scritto:

> On Fri, Jun 12, 2020 at 2:46 AM Catonano  wrote:
>
>> the original paper Andy Wingo refers to uses Haskell to express this
>> operator and I can't read Haskell and I'm not willing to learn
>>
>
> I'm confused about what you mean: in the version of "Applications of Fold
> to XML Transformation", on Andy Wingo's blog
> , all of the
> examples are in Scheme. Here is a version of the example from the paper
> that will run in Racket—most of the code is just copied and pasted from the
> figures
>


I'm referring to a paper titled: "A better XML parser through functional
programming"

by Oleg Kiselyov

I'd like to understand how exactly I'm supposed to arrange the "up" and
"down" functions that I should pass as arguments to Andy's operator

What are these operators supposed to take as arguments ?

And I was trying to start from the original paper Andy cites, because
that's where the original operator is defined (in haskell)

I know Andy's examples work

But I don't understand why they do and what I should do to apply that thing
to different use cases

i was trying to understand, not just running the examples

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAJ98PDwHPDrk8OcmKnS8FMwRiPfSY4VMFXZtMR5_gcxV6QKkWg%40mail.gmail.com.


Re: [racket-users] Re: Andy Wingo's fold

2020-06-12 Thread Philip McGrath
On Fri, Jun 12, 2020 at 2:46 AM Catonano  wrote:

> the original paper Andy Wingo refers to uses Haskell to express this
> operator and I can't read Haskell and I'm not willing to learn
>

I'm confused about what you mean: in the version of "Applications of Fold
to XML Transformation", on Andy Wingo's blog
, all of the
examples are in Scheme. Here is a version of the example from the paper
that will run in Racket—most of the code is just copied and pasted from the
figures:

#lang racket

;; Source: https://wingolog.org/pub/fold-and-xml-transformation.pdf

(module+ test
  (require rackunit)
  (check-equal?
   (cartouche->svg
;; figure 16
'(cartouche (@ (line-color "red")
   (text-height 56))
(para "Warning: Smoking Kills")))
   ;; figure 17
   '(g (rect (@ (fill "none") (stroke "red")
(stroke-width "4")
(width "660") (height "120.0")
(x "0") (y "0")
(ry "20")))
   (text (@ (xml:space "preserve")
(font-size "56")
(font-family "Georgia")
(x "32")
(y "88"))
 (tspan (@ (x "32") (y "88"))
"Warning: Smoking Kills")

;;
-
;;
-

;; for Racket compatibility

(define (atom? v)
  (not (pair? v)))

(struct layout (x y)
  #:constructor-name make-layout
  #:transparent)

;; p. 7
;;   "Figure 20 uses without definition the macro let-params,
;;which binds lexical variables from the parameters list."
;; p. 6
;;   "... representing parameters as a list of association lists.
;;At each descent into a new SXML node, we cons the new parameters
;;onto the list. Lookup proceeds left-to-right in the parameters list,
;;stopping at the first alist in which a parameter is found."
(require syntax/parse/define)
(define-simple-macro (let-params params:expr (name:id ...)
 body:expr ...+)
  (let ([the-params params])
(let ([name (params-ref the-params 'name)]
  ...)
  body ...)))
(define (params-ref params name)
  (or (for*/first ([alist (in-list params)]
   [pr (in-list alist)]
   #:when (eq? name (car pr)))
(cadr pr))
  (raise-argument-error 'params-ref "no binding found for parameter"
"name" name
"params" params)))

;;
-
;;
-


;; figure 7 (part)
(define (assq-ref alist key default)
  (cond ((assq key alist) => cdr)
(else default)))

;; figure 11
(define (fold-values proc list . seeds)
  (if (null? list)
  (apply values seeds)
  (call-with-values
   (lambda ()
 (apply proc (car list) seeds))
   (lambda seeds
 (apply fold-values proc (cdr list)
seeds)

;; figure 12
(define (foldts*-values fdown fup fhere
tree . seeds)
  (if (atom? tree)
  (apply fhere tree seeds)
  (call-with-values
   (lambda () (apply fdown tree seeds))
   (lambda (tree . kseeds)
 (call-with-values
  (lambda ()
(apply fold-values
   (lambda (tree . seeds)
 (apply foldts*-values
fdown fup fhere
tree seeds))
   tree kseeds))
  (lambda kseeds
(apply fup tree
   (append seeds kseeds

;; figure 13, but with fdown replaced by figure 14
(define (post-order bindings tree)
  (define (err . args)
(error "no binding available" args))
  (define (fdown tree bindings pcont ret)
(let ((tail (assq-ref bindings (car tree)
  #f)))
  (cond
((not tail)
 (let ((default (assq-ref bindings
  '*default* err)))
   (values tree bindings default '(
((pair? tail)
 (let ((cont (cdr tail)))
   (case (car tail)
 ((*preorder*)
  (values '() bindings
  (lambda x (reverse x))
  (apply cont tree)))
 ((*macro*)
  (fdown (apply cont tree) bindings
 pcont ret))
 (else
  (let ((new-bindings (append (car tail)
  bindings)))
(values tree new-bindings cont
'()))
(else
 (values tree bindings tail '())
  (define (fup tree bindings cont ret
   kbindings kcont kret)
(values bindings cont
(cons (apply kcont (reverse kret))
  

Re: [racket-users] Re: Andy Wingo's fold

2020-06-12 Thread Catonano
Hi Stephen,

Il giorno lun 8 giu 2020 alle ore 16:34 Stephen De Gabrielle <
spdegabrie...@gmail.com> ha scritto:

> Hi Catonano
>
> Did you resolve this
>
> Kind regards
>
> Stephen
>
>
>

No, I didn't resolve this

the original paper Andy Wingo refers to uses Haskell to express this
operator and I can't read Haskell and I'm not willing to learn

My idea was to use some drawings of trees made in svg and maybe animations
of trees being processed with the original operator (the one expressed in
Haskell)

There's a scheme implementation, in my idea I would have traced it while
running and I would have prepared a graphical representation

In order to explain the operator to myself, before than to anyone else

But frankly it's a lot of work

If this thing is expressed in such a poor way, maybe its authors are not
interested in this idea being a thing

I account this to the cultural debt of the scheme community

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAJ98PDy1fUw%3Dba6FrpNukiOSMf8XFf_PEFt2hmik%3D%2Bvt9i2-mg%40mail.gmail.com.


[racket-users] Re: Andy Wingo's fold

2020-06-08 Thread Stephen De Gabrielle
Hi Catonano 

Did you resolve this 

Kind regards

Stephen


On Saturday, March 21, 2020 at 9:16:14 AM UTC, Catonano wrote:
>
> Hi,
> in Guile there are some modules inspired by Andy Wingos paper: 
> "applications of fold to xml transformation"
>
> In Guile these concepts are used not only for xml processing but for tree 
> processing in general
>
> I was wondering if anything similar is available for Racket
>
> I'm having a hard time in processing a tree with such a fold procedure and 
> I could use some examples
>
> Thanks
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/3bdb5f57-622f-410f-9622-eee2659c9fcfo%40googlegroups.com.