views:

61

answers:

2

I'm trying to return an invisible value in a scheme function, but can't seem to get anything that WONT be printed to the screen, which is what I need. Is there a value in scheme that can be added to a list which won't be printed in a (display) call?

A: 

There is no standard way to do this. You can re-define the display procedure (or whatever output call on your Scheme) so that it do not print objects of a particular type.

(define display-old display)

(define (display obj)
     (if (not (invisible? obj))
         (display-old obj))) 
Vijay Mathew
+1  A: 

Instead of trying to create an invisible type, why don't you use filter to identify and remove the values you don't want to create a new list that you can then do whatever you like with, like print to screen.

(define (want-this? thing)
  ;; write a function that takes one
  ;;  parameter and returns a boolean
  ;;  true if you want it
  ;;  false if you don't
  )
(filter want-this?  '(v a l u e s))

Also see the docs: http://docs.racket-lang.org/reference/pairs.html?q=filter#%28def._%28%28lib._racket/private/base..rkt%29._filter%29%29

gnucom
It would be neat if SO syntax highlighting worked nicely for PLT-Racket. :P
gnucom