[racket] Question about path/param-path function

From: David T. Pierson (dtp at mindstory.com)
Date: Mon Feb 17 00:55:57 EST 2014

On Sun, Feb 16, 2014 at 08:19:48PM -0600, David Novogrodsky wrote:
> All,
> First here is the code I entered in the interaction window.  The question I have are about these lines:
> > (require xml net/url)
> > (define u (string->url "http://localhost:8080/foo/testing"))
> > (url-path u)
> '(#<path/param> #<path/param>)
> > (map path/param-path (url-path u))
> '("foo" "testing”)
> I took an online course on Systematic Programming and it used Racket for its examples.  Well, actually it used the intermediate learning language for the class.  now I am trying to learn Racket.

I had almost finished this response when I saw Professor Felleisen had
already responded.  Some of this is therefore redundant, but perhaps it
is useful for some additional context.

> The questions:
> 1. Take a look at the fourth line.  What is this called?  Is this a list of references or pointers?

It's a list of path/param objects.  I suspect you are thrown by the
funny-looking #<path/param> parts.  That is how opaque struct instances
are printed.  Structure printing is documented here:


but that has much more detail than you need right now, and very little
that applies to this example anyway.

> 2. I am trying to find if help-desk information about path/param-path
> function, but I have not been able to find any. 

When I search for `path/param-path' online I get:


which links to the docs for `path/param':


In case you aren't aware, a structure type `foo' with a field `bar' will
typically have an accessor function `foo-bar' which takes a foo instance
and returns the value of its bar field.  In this case, `path/param-path'
is the accessor function for the `path' field of a `path/param' object.

> This function returns returns the resolved parts of the path of a URL.
> What is the proper term for taking the list in line four and returning
> the list in line five?

I'm not sure what you are looking for here -- a word that means "using
`map'"?  I'm not a computer scientist, but maybe "mapping" or
"transforming"?  Perhaps you are referring to the fact that path/param
objects are wrappers or decorators around simple strings, so your map
operation is "unwrapping" or "deconstructing"?

> 3.  What is the proper term for what the function url-path returns?

A search for `url-path' brings me to:


which shows that the `path' field of a `url' object is a:

(listof path/param?)

In other words, `url-path' will return a list of `path/param' objects.

> 4.  Does anyone have an example of using the results from line 4 as part of a check-expect test?

(check-expect (map path/param-path (url-path u))
              (list "foo" "testing"))

I initially had trouble using check-expect directly with the result of
url-path, I think because of the problem described here:


If you want to learn Racket, you might want to switch the language
(control-L in DrRacket) to Racket, and use rackunit for unit testing:

#lang racket
(require net/url)
(require rackunit)
(define u (string->url "http://localhost:8080/foo/testing"))
(check-equal? (map path/param-path (url-path u))
              (list "foo" "testing"))


Posted on the users mailing list.