Hi David,

You can return nothing with (values). The function "values" returns
any number of values... (values 1 2 3) returns 3 values, (values 1)
returns 1 value, and (values) returns 0 values.

Jay

On Fri, Dec 11, 2015 at 1:16 AM, David K. Storrs <[email protected]> wrote:
> Question: Is there a way to make a function return nothing -- not '() or 
> #void, but actually nothing?
>
>
> I'm playing around with HTML parsing as a learning exercise.  The current 
> exercise is writing a look-down function which can be handed an HTML value 
> produced by the html library and a function, run the function across the 
> collect the results, and return them.  I would use this for things like "find 
> every link in the following document" or "capitalize every use of the word 
> 'kumquat'" or etc.
>
> I would like to have a way to say "this element isn't interesting, just 
> ignore it" so that I don't get spurious return values in the results list.  I 
> can't see a way to do that...I can exclude the values afterwards, but that's 
> not really what I was looking for, and opens the door to false negatives.
>
> Here's some simplified test code (removing all the HTML stuff for clarity) to 
> show the point:
>
>
> ----------------
> (define (foo-1 x) (if (eq? x "foo") #t '()))
> (define (foo-2 x) (if (eq? x "foo") #t (values)))
>
> (map foo-1 '(a b "foo" "bar"))
> (filter (lambda (x) (not (null? x))) (map foo-1 '(a b "foo" "bar")))
> (map foo-2 '(a b "foo" "bar"))
>
> [dstorrs@localhost:~/personal/study/scheme/spider:<master*>]$ racket test.rkt
> racket test.rkt
> '(() () #t ())
> '(#t)
> result arity mismatch;
>  expected number of values not received
>   expected: 1
>   received: 0
>   values...:
>   context...:
>    /Users/dstorrs/personal/study/scheme/spider/test.rkt: [running body]
> ----------------
>
> Instead of a 'result arity' crash, I would have liked to get '(#t) back, same 
> a if I'd generated the list and then filtered it.
>
> Is there a way to do this?
>
>
> For the record, here's the actual look-down function:
>
> (require (prefix-in h: html)
>          (prefix-in x: xml))
>
> (define (look-down el action)
>   (match el
>          [(struct h:html-full (attributes content))
>           (apply append (map action content))]
>
>          [(struct h:html-element (attributes))
>           (action el)]
>
>          [ _ '()]))
>
> --
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.



-- 
Jay McCarthy
Associate Professor
PLT @ CS @ UMass Lowell
http://jeapostrophe.github.io

           "Wherefore, be not weary in well-doing,
      for ye are laying the foundation of a great work.
And out of small things proceedeth that which is great."
                          - D&C 64:33

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to