6.2.2030 PICK CORE EXT

( xu...x1 x0 u -- xu...x1 x0 xu )

Remove u. Copy the xu to the top of the stack. An ambiguous condition exists if there are less than u+2 items on the stack before PICK is executed.

See:

Rationale:

0 PICK is equivalent to DUP and 1 PICK is equivalent to OVER.

ContributeContributions

ruvavatar of ruv [277] Example implementation for PICKSuggested reference implementation2023-02-10 21:51:27

: pick ( x0 i*x u.i -- x0 i*x x0 )
  dup 0= if drop dup exit then  swap >r 1- recurse r> swap
;

JimPetersonavatar of JimPeterson

I have always thought there could be a companion word to PICK, like this:

: place ( xu xu-1 ... x1 x0 y u -- y xu-1 ... x1 x0 )
  dup if rot >r 1- recurse r> exit then drop nip 
;

I think Anton wants "place" to mean something else to do with strings. Maybe this could be called "put"?

AntonErtlavatar of AntonErtl

I don't use PLACE, and I don't recommend that anybody uses it, but I recognize that there is a widely implemented word with that name that stores a counted string or somesuch.

Ulrich Hoffmann has proposed PLACE for standardization.

UlrichHoffmannavatar of UlrichHoffmann

Yes PLACE has a common meaning in systems influenced by F83. It's used to copy a string to a memory location ( c-addr1 u c-addr2 -- ) and place a length byte at addr2. So addr2 will then be a counted string (addr2 COUNT TYPE)... See the PLACE +PLACE proposal.

ruvavatar of ruvNew Version: Example implementation for PICK

Hide differences

: pick ( x0 ix u.i -- x0 ix x0 )

: pick ( x_u ... x_1 x_0 u -- x_u ... x_1 x_0 x_u )

dup 0= if drop dup exit then swap >r 1- recurse r> swap ;


(the stack diagram is copied from the glossary entry)

ruvavatar of ruvNew Version: Example implementation for PICK

Hide differences
: pick ( x_u ... x_1 x_0 u -- x_u ... x_1 x_0 x_u )
  dup 0= if drop dup exit then  swap >r 1- recurse r> swap
;

(the stack diagram is copied from the glossary entry)

Reply New Version

gethboavatar of gethbo [363] Clarification on what constitutes an ambiguous condition for this word.Request for clarification2024-09-19 14:31:15

The description for this word says: "...An ambiguous condition exists if there are less than u+2 items on the stack before PICK is executed"

In this example with 3 items on the stack: (x2 x1 x0 2 -- x2 x1 x0 x2)

This example worked in gforth - However u+2 = 4 and since 3 < 4 this is an ambiguous condition.

I might be missing something here but shouldn't this read : "An ambiguous condition exists if there are less than u+1 items on the stack before PICK is executed"

AntonErtlavatar of AntonErtl

In your example there are 4 items on the stack. You have to count the 2, too.

Closed
Reply New Version