Re: [racket-users] For/lists: where is #:continue?

2015-07-13 Thread Jon Zeppieri
I think you're looking for #:when / #:unless.

On Mon, Jul 13, 2015 at 3:12 PM, Pekka Niiranen
pekka.niira...@pp5.inet.fi wrote:
 Hello users,

 What is the proper design pattern to skip invalid values
 when using for/list?

 The programs below fails because #:continue is not recognized:

 for/list ([i (in-range 0 1000)])
   (let ((value (vector-ref vector i)))
 (if ( 0 (length value))
 value
 #:continue)))

 Sure, I could bypass this limitation by building the list explicitely
 with plain for + cons or:

 (define result-list
   (for/list ([i (in-range 0 1000)])
 (let ((value (vector-ref vector i)))
   (if ( 0 (length value))
   value
   empty

 = then filter empties from result-list with another loop...

 -pekka-


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

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


Re: [racket-users] For/lists: where is #:continue?

2015-07-13 Thread Jon Zeppieri
Also, since you're not actually interested in the value of i, you
should probably use in-vector rather than in-range. The whole example
would be:

(for/list ([value (in-vector vector)]
   #:when ( 0 (length value)))
  value)


On Mon, Jul 13, 2015 at 3:18 PM, Jon Zeppieri zeppi...@gmail.com wrote:
 I think you're looking for #:when / #:unless.

 On Mon, Jul 13, 2015 at 3:12 PM, Pekka Niiranen
 pekka.niira...@pp5.inet.fi wrote:
 Hello users,

 What is the proper design pattern to skip invalid values
 when using for/list?

 The programs below fails because #:continue is not recognized:

 for/list ([i (in-range 0 1000)])
   (let ((value (vector-ref vector i)))
 (if ( 0 (length value))
 value
 #:continue)))

 Sure, I could bypass this limitation by building the list explicitely
 with plain for + cons or:

 (define result-list
   (for/list ([i (in-range 0 1000)])
 (let ((value (vector-ref vector i)))
   (if ( 0 (length value))
   value
   empty

 = then filter empties from result-list with another loop...

 -pekka-


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

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


Re: [racket-users] For/lists: where is #:continue?

2015-07-13 Thread Jon Zeppieri
In that case, you probably want to make use of in-value to bind
single-value sequences in your for*/list:

(for*/list ([(start end) (in-parallel 1 1000)]
[i (in-range start (sub1 end))]
[s (in-value (vector-ref vector i))]
[columns (in-value (string-split s ,))]
[col# (in-value (length columns))]
#:when ( 2 col#))
  (first columns))

On Mon, Jul 13, 2015 at 3:46 PM, Pekka Niiranen
pekka.niira...@pp5.inet.fi wrote:
 Hello Sir.

 all true, but my example was bad simplification from the original code.

 The ugly part is to insert the multi-step function into #:when -clause
 and in case of success use function's internal parameter (columns) only.
 My imperative mind wants to use continue in the place empty below:

 (for*/list ([(start end) (in-parallel 1 1000)]
[i (in-range start (sub1 end))])
   (let* ((columns (string-split (vector-ref vector i) ,))
  (col# (length columns)))
 (if ( 2 col#)
 (first columns)
 empty)))



 On 7/13/15 10:26 PM, Jon Zeppieri wrote:

 Also, since you're not actually interested in the value of i, you
 should probably use in-vector rather than in-range. The whole example
 would be:

 (for/list ([value (in-vector vector)]
 #:when ( 0 (length value)))
value)


 On Mon, Jul 13, 2015 at 3:18 PM, Jon Zeppieri zeppi...@gmail.com wrote:

 I think you're looking for #:when / #:unless.

 On Mon, Jul 13, 2015 at 3:12 PM, Pekka Niiranen
 pekka.niira...@pp5.inet.fi wrote:

 Hello users,

 What is the proper design pattern to skip invalid values
 when using for/list?

 The programs below fails because #:continue is not recognized:

 for/list ([i (in-range 0 1000)])
(let ((value (vector-ref vector i)))
  (if ( 0 (length value))
  value
  #:continue)))

 Sure, I could bypass this limitation by building the list explicitely
 with plain for + cons or:

 (define result-list
(for/list ([i (in-range 0 1000)])
  (let ((value (vector-ref vector i)))
(if ( 0 (length value))
value
empty

 = then filter empties from result-list with another loop...

 -pekka-


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



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