Re: [racket-users] for loop: any way to access the whole list?

2019-06-15 Thread Sanjeev Sharma
thanks, 

the whole idea is to localize the identifiers to the for (preferred) or the 
let*. 

Reaching back to get the whole list when the for has bound the same 
identifier is probably asking a bit much.

Within the given strictures I probably need to bind the list in the let* 
and use a different identifier in the for().


On Friday, June 14, 2019 at 12:46:54 PM UTC-4, David Storrs wrote:
>
>
>
> On Fri, Jun 14, 2019 at 10:45 AM Sanjeev Sharma  > wrote:
>
>> within this for loop is there any way to access different pieces of the 
>> description and amt?  car-ing and cdr-ing for example?
>>
>
> I'm not entirely clear on what you're looking for, but maybe this helps?
>
> (define lst '(a b c))
> (for ([(val idx) (in-indexed lst)]) 
>   (displayln (cons  val idx)) 
>   (when (< idx (sub1 (length lst))) 
> (displayln (format "\tnext val: ~a" (list-ref lst (add1 idx)) 
>
> Output:
> (a . 0)
> next val: b
> (b . 1)
> next val: c
> (c . 2)
>
>
>> Or move the identifier definitions into the let*, and pass those to for 
>> in some way?
>>
>> (let*((ratio 9/12))
>>   (for((description(list "this" "that"))
>>(amt(list 4467.61 2428.37)))
>> (printf"~a ~a: changed values\n"
>>description
>>(cat(* amt ratio) -2.
>>
>> -- 
>> 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...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/racket-users/07ad5ce3-0ba8-48a5-a356-5cb1545de4cd%40googlegroups.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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/cd979a18-c099-42b3-99f9-48ce099da19d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] for loop: any way to access the whole list?

2019-06-14 Thread David Storrs
On Fri, Jun 14, 2019 at 10:45 AM Sanjeev Sharma  wrote:

> within this for loop is there any way to access different pieces of the
> description and amt?  car-ing and cdr-ing for example?
>

I'm not entirely clear on what you're looking for, but maybe this helps?

(define lst '(a b c))
(for ([(val idx) (in-indexed lst)])
  (displayln (cons  val idx))
  (when (< idx (sub1 (length lst)))
(displayln (format "\tnext val: ~a" (list-ref lst (add1 idx))

Output:
(a . 0)
next val: b
(b . 1)
next val: c
(c . 2)


> Or move the identifier definitions into the let*, and pass those to for in
> some way?
>
> (let*((ratio 9/12))
>   (for((description(list "this" "that"))
>(amt(list 4467.61 2428.37)))
> (printf"~a ~a: changed values\n"
>description
>(cat(* amt ratio) -2.
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/07ad5ce3-0ba8-48a5-a356-5cb1545de4cd%40googlegroups.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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAE8gKoenWYdDgchNr5-T_UzDbNb3uzgL%3DKxQv8a2U2DmXXSedA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [racket-users] for loop: any way to access the whole list?

2019-06-14 Thread Jens Axel Søgaard
I am not entirely sure this answer is what you are looking for, but the
following generator
will produce the pairs of the list instead of the elements.

(define (in-pairs xs)
  (make-do-sequence
   (λ ()
 (define (pos->element p) p)
 (define (next-position p) (cdr p))
 (define initial-position xs)
 (define (continue-with-pos? p) (pair? p))
 (values pos->element
 next-position
 initial-position
 continue-with-pos?
 #f #f

Example:

>* (for ([p (in-pairs '(1 2 3 4))])
*(displayln p))
(1 2 3 4)
(2 3 4)
(3 4)
(4)

So you can use

(define descriptions (list "this" "that"))
(define amounts  (list 4467.61 2428.37))
(for ([d descriptions] [ds (in-pairs descriptions)])
  [a amounts]  [as (in-pairs amounts])
   ...)

And use ds and as to get to other descriptions/amounts than the current
(which are in d and a).

/Jens Axel



Den fre. 14. jun. 2019 kl. 16.45 skrev Sanjeev Sharma :

> within this for loop is there any way to access different pieces of the
> description and amt?  car-ing and cdr-ing for example?
>
> Or move the identifier definitions into the let*, and pass those to for in
> some way?
>
> (let*((ratio 9/12))
>   (for((description(list "this" "that"))
>(amt(list 4467.61 2428.37)))
> (printf"~a ~a: changed values\n"
>description
>(cat(* amt ratio) -2.
>
> --
> 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.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/07ad5ce3-0ba8-48a5-a356-5cb1545de4cd%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>


-- 
-- 
Jens Axel Søgaard

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CABefVgzj7eyxCpoq%3D3ULbeZ9-BsDkPj50RZa%3D-nhQxnf65u4rg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[racket-users] for loop: any way to access the whole list?

2019-06-14 Thread Sanjeev Sharma
within this for loop is there any way to access different pieces of the 
description and amt?  car-ing and cdr-ing for example?

Or move the identifier definitions into the let*, and pass those to for in 
some way?

(let*((ratio 9/12))
  (for((description(list "this" "that"))
   (amt(list 4467.61 2428.37)))
(printf"~a ~a: changed values\n"
   description
   (cat(* amt ratio) -2.

-- 
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.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/07ad5ce3-0ba8-48a5-a356-5cb1545de4cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.