Add word q:poke

  • 10 Replies
  • 112 Views
*

sukoi

  • Apprentice
  • **
  • 40
Add word q:poke
« on: April 18, 2017, 22:11:25 »
It will be nice to have this word  to poke the value of an items of the queue.

with peek i have only the first item
ok> stock @ q:peek . cr
{"qt":20,"type":2,"of":1}

will give
ok> stock @  5 q:poke . cr
{"qt":50,"type":2,"of":5}

 the reason,  how to have the n item value of the queue without touch the items of the queue?
(case display the queue )

*

ron

  • Administrator
  • Guru
  • *****
  • 3,243
Re: Add word q:poke
« Reply #1 on: April 19, 2017, 04:47:12 »
I was thinking of adding "st:poke" to be the opposite of "st:pick".  I suppose adding queue words with the equivalent functionality could also be done.

*

sukoi

  • Apprentice
  • **
  • 40
Re: Add word q:poke
« Reply #2 on: April 19, 2017, 18:51:27 »
yes, perhaps q:get or q:set  , can be a similar word used in other language libraries. 

*

ron

  • Administrator
  • Guru
  • *****
  • 3,243
Re: Add word q:poke
« Reply #3 on: April 19, 2017, 19:23:14 »
I prefer to reuse words we're already using, with similar functionality.

*

sukoi

  • Apprentice
  • **
  • 40
Re: Add word q:poke
« Reply #4 on: April 20, 2017, 18:20:42 »
in waiting , i need to display the queue, which is the best way to do that ?
i imagine  to make a copy of the queue ,  and a loop to print.

How to make a copy of the queue ?

*

ron

  • Administrator
  • Guru
  • *****
  • 3,243
Re: Add word q:poke
« Reply #5 on: April 20, 2017, 18:28:37 »
I'm sorry to say, that there isn't a good way to do that.

You would have to loop on the queue, and fill a second one, then refill the first.

*

sukoi

  • Apprentice
  • **
  • 40
Re: Add word q:poke
« Reply #6 on: April 20, 2017, 23:07:56 »
thanks

*

ron

  • Administrator
  • Guru
  • *****
  • 3,243
Re: Add word q:poke
« Reply #7 on: April 21, 2017, 05:31:02 »
Hi -

I overlooked "clone", which will clone a container as well as its contents:
Code: [Select]
10 q:new
100 q:push 200 q:push
.s
clone
.s
q:pop . cr
.s

The output shows two different queues, with 2 items, and shows they are not the same queue when popping from the clone.

*

sukoi

  • Apprentice
  • **
  • 40
Re: Add word q:poke
« Reply #8 on: April 21, 2017, 19:06:53 »
better,  one thing ,
if  b is a clone queue of a wit 2 items
after 2 b  queue pop i receive null items
on  a queue an error empty queue
Code: [Select]
ok> null var, a
ok> null var, b
ok> 10 q:new a !
ok> a @ 10 q:push
ok> a @ 11 q:push . cr
2 items
ok> a @  clone  b !
ok> b @ .
2 items
ok> b @ q:pop . cr
10
ok> b @ q:pop . cr
11
ok> b @ q:pop . cr
null
ok> b @ q:pop . cr
null
ok> a  @ q:pop . cr
10
ok> a  @ q:pop . cr
11
ok> a  @ q:pop . cr
Exception: queue empty: at offset 11 in console: pop (G:;;; +000001a8)
0 items
ok>

*

ron

  • Administrator
  • Guru
  • *****
  • 3,243
Re: Add word q:poke
« Reply #9 on: April 22, 2017, 18:21:55 »
OK, so that is a bug: please do make a bug report for it.

I think the cloned queue doesn't have the 'throw exception' flag from the original.
« Last Edit: April 22, 2017, 18:42:46 by ron »

*

ron

  • Administrator
  • Guru
  • *****
  • 3,243
Re: Add word q:poke
« Reply #10 on: April 23, 2017, 14:26:03 »
Well.

There turned out to be a number of issues, and they're fixed for 17.04.  Thank you for reporting this!