Hello, fede s!
Thank you for pointing me in the right direction. The following code works:
USING: slots.macros ;
TYPED: maybe-prepend-slot (
res: resource-gadget
str: string
slot-name: string
--
res: resource-gadget
str: string
added?
)
[ over res>> ] dip slot [ [ " - " append prepend ] when* ] keep ; inline
TYPED: maybe-prepend-name ( res: resource-gadget str: string
-- res: resource-gadget str': string added? )
"name" maybe-prepend-slot ;
TYPED: maybe-prepend-root ( res: resource-gadget str: string
-- res: resource-gadget str': string added? )
"root" maybe-prepend-slot ;
23.05.2017, 02:08, "fede s" <elfeder...@yahoo.com.ar>:
,Hi, looks like you could make a word for that, using "slot-named" and "slot" from the "slots" vocab.Something like:USING: slots ;: slot-by-name>> ( object name -- value )slot-named ! returns a slot-specoffset>> ! the offset of that slotslot ;But haven't tried it...
El Viernes, 19 de mayo, 2017 14:07:46, Alexander Ilin <ajs...@yandex.ru> escribió:Hello!Is there a way to generalize this code?TYPED: maybe-prepend-name ( res: resource-gadget str: string-- res: resource-gadget str: string added?: boolean )over res>> name>> [ [ " - " append prepend ] when* ] keep >boolean ;TYPED: maybe-prepend-root ( res: resource-gadget str: string-- res: resource-gadget str: string added?: boolean )over res>> root>> [ [ " - " append prepend ] when* ] keep >boolean ;The only difference between the two words is in the slot name.---=====---Александр------------------------------------------------------------------------------Check out the vibrant tech community on one of the world's mostengaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________Factor-talk mailing list
------------------------------------------------------------------------------
,
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk
---=====---
Александр
------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________ Factor-talk mailing list Factor-talk@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/factor-talk