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: [277] 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: [277] 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