[racket] Question about path/param-path function

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sun Feb 16 22:22:44 EST 2014



On Feb 16, 2014, at 9:19 PM, 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.

Systematic Programming is derived from 'How to Design Programs'. As you say, it doesn't teach Racket per se; it teaches a certain way to think about programming, namely, designing programs vs garage programming. 

>  now I am trying to learn Racket.

Consider 'Realm of Racket.' It is considered a bridge between HtDP and Racket proper. 


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

You get a list of structure instances. 


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


It's right here: 

 http://docs.racket-lang.org/net/url.html?q=path/param#%28def._%28%28lib._net%2Furl-structs..rkt%29._path%2Fparam%29%29

I double-checked and it is also in the local docs. 


> 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?

The docs say you have structure instances here (instances of path/param). 



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

A list of structure instances. 


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


a -- 

#lang racket

(require net/url test-engine/racket-tests)

(check-expect (list (path/param "x" '()) (path/param "y" '()))
              (list (path/param "x" '()) (path/param "y" '())))

(test)

When you run this, you will see that the result is negative (the test case fails). Why? The struct is opaque, meaning the test engine can't look inside. 

b -- 

As you grow into Racket (see Realm), you will use the test engine for adults (well one of them): 

#lang racket

(require net/url rackunit)

(check-equal? (list (path/param "x" '()) (path/param "y" '()))
              (list (path/param "x" '()) (path/param "y" '())))


It still gives you a test failure, for the same reason. 

c -- 

That's why someone told you to use path/param-path: 

#lang racket

(require net/url rackunit)

(define p (list (path/param "x" '()) (path/param "y" '())))

(check-equal? (map path/param-path p)
              '("x" "y"))


And when you run this, the test succeeds.





> 
> 
> David Novogrodsky
> david.novogrodsky at gmail.com
> http://www.linkedin.com/in/davidnovogrodsky
> 
> 
> 
> 
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users



Posted on the users mailing list.