implement HELP

This commit is contained in:
Gwenhael Le Moine 2022-02-09 16:38:09 +01:00
parent 912ca03f9c
commit 195ebb37b7
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
3 changed files with 502 additions and 313 deletions

View file

@ -142,383 +142,557 @@ module Rpl
def populate_dictionary def populate_dictionary
# GENERAL # GENERAL
@dictionary.add( 'nop', @dictionary.add_word( ['nop'],
'General',
'( -- ) no operation',
proc { |stack, dictionary| Rpl::Lang::Core.nop( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.nop( stack, dictionary ) } )
# @dictionary.add( 'help', @dictionary.add_word( ['help'],
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # this help message 'General',
# @dictionary.add( 'quit', '( w -- s ) pop help string of the given word',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # quit software proc { |stack, dictionary| Rpl::Lang::Core.help( stack, dictionary ) } )
# @dictionary.add( 'version', @dictionary.add_word( ['quit'],
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # show rpn version 'General',
# @dictionary.add( 'uname', '( -- ) Stop and quit interpreter',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # show rpn complete identification string proc { |stack, dictionary| } )
# @dictionary.add( 'history', @dictionary.add_word( ['version'],
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # see commands history 'General',
@dictionary.add( '__ppstack', '( -- n ) Pop the interpreter\'s version number',
proc { |stack, dictionary| Rpl::Lang::Core.version( stack, dictionary ) } )
@dictionary.add_word( ['uname'],
'General',
'( -- s ) Pop the interpreter\'s complete indentification string',
proc { |stack, dictionary| Rpl::Lang::Core.uname( stack, dictionary ) } )
@dictionary.add_word( ['history'],
'REPL',
'',
proc { |stack, dictionary| } )
@dictionary.add_word( ['__ppstack'],
'REPL',
'DEBUG',
proc { |stack, dictionary| Rpl::Lang.__pp_stack( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang.__pp_stack( stack, dictionary ) } )
# STACK # STACK
@dictionary.add( 'swap', @dictionary.add_word( ['swap'],
'Stack',
'( a b -- b a ) swap 2 first stack elements',
proc { |stack, dictionary| Rpl::Lang::Core.swap( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.swap( stack, dictionary ) } )
@dictionary.add( 'drop', @dictionary.add_word( ['drop'],
'Stack',
'( a -- ) drop first stack element',
proc { |stack, dictionary| Rpl::Lang::Core.drop( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.drop( stack, dictionary ) } )
@dictionary.add( 'drop2', @dictionary.add_word( ['drop2'],
'Stack',
'( a b -- ) drop first two stack elements',
proc { |stack, dictionary| Rpl::Lang::Core.drop2( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.drop2( stack, dictionary ) } )
@dictionary.add( 'dropn', @dictionary.add_word( ['dropn'],
'Stack',
'( a b … n -- ) drop first n stack elements',
proc { |stack, dictionary| Rpl::Lang::Core.dropn( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.dropn( stack, dictionary ) } )
@dictionary.add( 'del', @dictionary.add_word( ['del'],
'Stack',
'( a b … -- ) drop all stack elements',
proc { |stack, dictionary| Rpl::Lang::Core.del( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.del( stack, dictionary ) } )
@dictionary.add( 'rot', @dictionary.add_word( ['rot'],
'Stack',
'( a b c -- b c a ) rotate 3 first stack elements',
proc { |stack, dictionary| Rpl::Lang::Core.rot( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.rot( stack, dictionary ) } )
@dictionary.add( 'dup', @dictionary.add_word( ['dup'],
'Stack',
'( a -- a a ) duplicate first stack element',
proc { |stack, dictionary| Rpl::Lang::Core.dup( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.dup( stack, dictionary ) } )
@dictionary.add( 'dup2', @dictionary.add_word( ['dup2'],
'Stack',
'( a b -- a b a b ) duplicate first two stack elements',
proc { |stack, dictionary| Rpl::Lang::Core.dup2( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.dup2( stack, dictionary ) } )
@dictionary.add( 'dupn', @dictionary.add_word( ['dupn'],
'Stack',
'( a b … n -- a b … a b … ) duplicate first n stack elements',
proc { |stack, dictionary| Rpl::Lang::Core.dupn( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.dupn( stack, dictionary ) } )
@dictionary.add( 'pick', @dictionary.add_word( ['pick'],
'Stack',
'( … b … n -- … b … b ) push a copy of the given stack level onto the stack',
proc { |stack, dictionary| Rpl::Lang::Core.pick( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.pick( stack, dictionary ) } )
@dictionary.add( 'depth', @dictionary.add_word( ['depth'],
'Stack',
'( … -- … n ) push stack depth onto the stack',
proc { |stack, dictionary| Rpl::Lang::Core.depth( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.depth( stack, dictionary ) } )
@dictionary.add( 'roll', @dictionary.add_word( ['roll'],
'Stack',
'( … a -- a … ) move a stack element to the top of the stack',
proc { |stack, dictionary| Rpl::Lang::Core.roll( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.roll( stack, dictionary ) } )
@dictionary.add( 'rolld', @dictionary.add_word( ['rolld'],
'Stack',
'( a … -- … a ) move the element on top of the stack to a higher stack position',
proc { |stack, dictionary| Rpl::Lang::Core.rolld( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.rolld( stack, dictionary ) } )
@dictionary.add( 'over', @dictionary.add_word( ['over'],
'Stack',
'( a b -- a b a ) push a copy of the element in stack level 2 onto the stack',
proc { |stack, dictionary| Rpl::Lang::Core.over( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.over( stack, dictionary ) } )
# USUAL OPERATIONS ON REALS AND COMPLEXES # Usual operations on reals and complexes
@dictionary.add( '+', @dictionary.add_word( ['+'],
'Usual operations on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.add( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.add( stack, dictionary ) } )
@dictionary.add( '-', @dictionary.add_word( ['-'],
'Usual operations on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.subtract( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.subtract( stack, dictionary ) } )
@dictionary.add( 'chs', @dictionary.add_word( ['chs'],
'Usual operations on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.negate( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.negate( stack, dictionary ) } )
@dictionary.add( '*', @dictionary.add_word( ['×', '*'],
'Usual operations on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.multiply( stack, dictionary ) } ) # alias proc { |stack, dictionary| Rpl::Lang::Core.multiply( stack, dictionary ) } ) # alias
@dictionary.add( '×', @dictionary.add_word( ['÷', '/'],
proc { |stack, dictionary| Rpl::Lang::Core.multiply( stack, dictionary ) } ) 'Usual operations on reals and complexes',
@dictionary.add( '/', '',
proc { |stack, dictionary| Rpl::Lang::Core.divide( stack, dictionary ) } ) # alias proc { |stack, dictionary| Rpl::Lang::Core.divide( stack, dictionary ) } ) # alias
@dictionary.add( '÷', @dictionary.add_word( ['inv'],
proc { |stack, dictionary| Rpl::Lang::Core.divide( stack, dictionary ) } ) 'Usual operations on reals and complexes',
@dictionary.add( 'inv', '',
proc { |stack, dictionary| Rpl::Lang::Core.inverse( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.inverse( stack, dictionary ) } )
@dictionary.add( '^', @dictionary.add_word( ['^'],
'Usual operations on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.power( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.power( stack, dictionary ) } )
@dictionary.add( 'sqrt', @dictionary.add_word( ['√', 'sqrt'],
'Usual operations on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.sqrt( stack, dictionary ) } ) # alias proc { |stack, dictionary| Rpl::Lang::Core.sqrt( stack, dictionary ) } ) # alias
@dictionary.add( '√', @dictionary.add_word( ['²', 'sq'],
proc { |stack, dictionary| Rpl::Lang::Core.sqrt( stack, dictionary ) } ) 'Usual operations on reals and complexes',
@dictionary.add( 'sq', '',
proc { |stack, dictionary| Rpl::Lang::Core.sq( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.sq( stack, dictionary ) } )
@dictionary.add( 'abs', @dictionary.add_word( ['abs'],
'Usual operations on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.abs( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.abs( stack, dictionary ) } )
@dictionary.add( 'dec', @dictionary.add_word( ['dec'],
'Usual operations on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.dec( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.dec( stack, dictionary ) } )
@dictionary.add( 'hex', @dictionary.add_word( ['hex'],
'Usual operations on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.hex( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.hex( stack, dictionary ) } )
@dictionary.add( 'bin', @dictionary.add_word( ['bin'],
'Usual operations on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.bin( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.bin( stack, dictionary ) } )
@dictionary.add( 'base', @dictionary.add_word( ['base'],
'Usual operations on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.base( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.base( stack, dictionary ) } )
@dictionary.add( 'sign', @dictionary.add_word( ['sign'],
'Usual operations on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.sign( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.sign( stack, dictionary ) } )
# OPERATIONS ON REALS # Operations on reals
@dictionary.add( '%', @dictionary.add_word( ['%'],
'Operations on reals',
'',
proc { |stack, dictionary| Rpl::Lang::Core.percent( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.percent( stack, dictionary ) } )
@dictionary.add( '%CH', @dictionary.add_word( ['%CH'],
'Operations on reals',
'',
proc { |stack, dictionary| Rpl::Lang::Core.inverse_percent( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.inverse_percent( stack, dictionary ) } )
@dictionary.add( 'mod', @dictionary.add_word( ['mod'],
'Operations on reals',
'',
proc { |stack, dictionary| Rpl::Lang::Core.mod( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.mod( stack, dictionary ) } )
@dictionary.add( 'fact', @dictionary.add_word( ['!', 'fact'],
'Operations on reals',
'',
proc { |stack, dictionary| Rpl::Lang::Core.fact( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.fact( stack, dictionary ) } )
@dictionary.add( '!', @dictionary.add_word( ['floor'],
proc { |stack, dictionary| Rpl::Lang::Core.fact( stack, dictionary ) } ) # alias 'Operations on reals',
@dictionary.add( 'floor', '',
proc { |stack, dictionary| Rpl::Lang::Core.floor( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.floor( stack, dictionary ) } )
@dictionary.add( 'ceil', @dictionary.add_word( ['ceil'],
'Operations on reals',
'',
proc { |stack, dictionary| Rpl::Lang::Core.ceil( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.ceil( stack, dictionary ) } )
@dictionary.add( 'min', @dictionary.add_word( ['min'],
'Operations on reals',
'',
proc { |stack, dictionary| Rpl::Lang::Core.min( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.min( stack, dictionary ) } )
@dictionary.add( 'max', @dictionary.add_word( ['max'],
'Operations on reals',
'',
proc { |stack, dictionary| Rpl::Lang::Core.max( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.max( stack, dictionary ) } )
# @dictionary.add( 'mant', # @dictionary.add_word( ['mant'],
# 'Operations on reals',
# '',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # mantissa of a real number # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # mantissa of a real number
# @dictionary.add( 'xpon', # @dictionary.add_word( ['xpon'],
# 'Operations on reals',
# '',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # exponant of a real number # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # exponant of a real number
# @dictionary.add( 'ip', # @dictionary.add_word( ['ip'],
# 'Operations on reals',
# '',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # integer part # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # integer part
# @dictionary.add( 'fp', # @dictionary.add_word( ['fp'],
# 'Operations on reals',
# '',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # fractional part # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # fractional part
# OPERATIONS ON COMPLEXES # OPERATIONS ON COMPLEXES
# @dictionary.add( 're', # @dictionary.add_word( ['re'],
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # complex real part # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # complex real part
# @dictionary.add( 'im', # @dictionary.add_word( 'im',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # complex imaginary part # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # complex imaginary part
# @dictionary.add( 'conj', # @dictionary.add_word( ['conj'],
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # complex conjugate # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # complex conjugate
# @dictionary.add( 'arg', # @dictionary.add_word( 'arg',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # complex argument in radians # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # complex argument in radians
# @dictionary.add( 'c->r', # @dictionary.add_word( ['c->r'],
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # transform a complex in 2 reals # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # transform a complex in 2 reals
# @dictionary.add( 'c→r', # @dictionary.add_word( 'c→r',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # alias # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # alias
# @dictionary.add( 'r->c', # @dictionary.add_word( ['r->c'],
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # transform 2 reals in a complex # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # transform 2 reals in a complex
# @dictionary.add( 'r→c', # @dictionary.add_word( 'r→c',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # alias # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # alias
# @dictionary.add( 'p->r', # @dictionary.add_word( ['p->r'],
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # cartesian to polar # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # cartesian to polar
# @dictionary.add( 'p→r', # @dictionary.add_word( 'p→r',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # alias # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # alias
# @dictionary.add( 'r->p', # @dictionary.add_word( ['r->p'],
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # polar to cartesian # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # polar to cartesian
# @dictionary.add( 'r→p', # @dictionary.add_word( 'r→p',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # alias # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # alias
# MODE # Mode
@dictionary.add( 'prec', @dictionary.add_word( ['prec'],
'Mode',
'',
proc { |stack, dictionary| Rpl::Lang::Core.prec( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.prec( stack, dictionary ) } )
@dictionary.add( 'default', @dictionary.add_word( ['default'],
'Mode',
'',
proc { |stack, dictionary| Rpl::Lang::Core.default( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.default( stack, dictionary ) } )
@dictionary.add( 'type', @dictionary.add_word( ['type'],
'Mode',
'',
proc { |stack, dictionary| Rpl::Lang::Core.type( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.type( stack, dictionary ) } )
# @dictionary.add( 'std', # @dictionary.add_word( ['std'],
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # standard floating numbers representation. ex: std # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # standard floating numbers representation. ex: std
# @dictionary.add( 'fix', # @dictionary.add_word( ['fix'],
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # fixed point representation. ex: 6 fix # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # fixed point representation. ex: 6 fix
# @dictionary.add( 'sci', # @dictionary.add_word( ['sci'],
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # scientific floating point representation. ex: 20 sci # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # scientific floating point representation. ex: 20 sci
# @dictionary.add( 'round', # @dictionary.add_word( ['round'],
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # set float rounding mode. ex: ["nearest", "toward zero", "toward +inf", "toward -inf", "away from zero"] round # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # set float rounding mode. ex: ["nearest", "toward zero", "toward +inf", "toward -inf", "away from zero"] round
# TEST # Test
@dictionary.add( '>', @dictionary.add_word( ['>'],
'Test',
'',
proc { |stack, dictionary| Rpl::Lang::Core.greater_than( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.greater_than( stack, dictionary ) } )
@dictionary.add( '>=', @dictionary.add_word( ['≥', '>='],
'Test',
'',
proc { |stack, dictionary| Rpl::Lang::Core.greater_than_or_equal( stack, dictionary ) } ) # alias proc { |stack, dictionary| Rpl::Lang::Core.greater_than_or_equal( stack, dictionary ) } ) # alias
@dictionary.add( '≥', @dictionary.add_word( ['<'],
proc { |stack, dictionary| Rpl::Lang::Core.greater_than_or_equal( stack, dictionary ) } ) 'Test',
@dictionary.add( '<', '',
proc { |stack, dictionary| Rpl::Lang::Core.less_than( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.less_than( stack, dictionary ) } )
@dictionary.add( '<=', @dictionary.add_word( ['≤', '<='],
'Test',
'',
proc { |stack, dictionary| Rpl::Lang::Core.less_than_or_equal( stack, dictionary ) } ) # alias proc { |stack, dictionary| Rpl::Lang::Core.less_than_or_equal( stack, dictionary ) } ) # alias
@dictionary.add( '≤', @dictionary.add_word( ['≠', '!='],
proc { |stack, dictionary| Rpl::Lang::Core.less_than_or_equal( stack, dictionary ) } ) 'Test',
@dictionary.add( '!=', '',
proc { |stack, dictionary| Rpl::Lang::Core.different( stack, dictionary ) } ) # alias proc { |stack, dictionary| Rpl::Lang::Core.different( stack, dictionary ) } ) # alias
@dictionary.add( '≠', @dictionary.add_word( ['==', 'same'],
proc { |stack, dictionary| Rpl::Lang::Core.different( stack, dictionary ) } ) 'Test',
@dictionary.add( '==', '',
proc { |stack, dictionary| Rpl::Lang::Core.same( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.same( stack, dictionary ) } )
@dictionary.add( 'and', @dictionary.add_word( ['and'],
'Test',
'',
proc { |stack, dictionary| Rpl::Lang::Core.and( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.and( stack, dictionary ) } )
@dictionary.add( 'or', @dictionary.add_word( ['or'],
'Test',
'',
proc { |stack, dictionary| Rpl::Lang::Core.or( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.or( stack, dictionary ) } )
@dictionary.add( 'xor', @dictionary.add_word( ['xor'],
'Test',
'',
proc { |stack, dictionary| Rpl::Lang::Core.xor( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.xor( stack, dictionary ) } )
@dictionary.add( 'not', @dictionary.add_word( ['not'],
'Test',
'',
proc { |stack, dictionary| Rpl::Lang::Core.not( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.not( stack, dictionary ) } )
@dictionary.add( 'same', @dictionary.add_word( ['true'],
proc { |stack, dictionary| Rpl::Lang::Core.same( stack, dictionary ) } ) # alias 'Test',
@dictionary.add( 'true', '',
proc { |stack, dictionary| Rpl::Lang::Core.true( stack, dictionary ) } ) # specific proc { |stack, dictionary| Rpl::Lang::Core.true( stack, dictionary ) } ) # specific
@dictionary.add( 'false', @dictionary.add_word( ['false'],
'Test',
'',
proc { |stack, dictionary| Rpl::Lang::Core.false( stack, dictionary ) } ) # specific proc { |stack, dictionary| Rpl::Lang::Core.false( stack, dictionary ) } ) # specific
# STRING # String
@dictionary.add( '->str', @dictionary.add_word( ['→str', '->str'],
'String',
'',
proc { |stack, dictionary| Rpl::Lang::Core.to_string( stack, dictionary ) } ) # alias proc { |stack, dictionary| Rpl::Lang::Core.to_string( stack, dictionary ) } ) # alias
@dictionary.add( '→str', @dictionary.add_word( ['str→', 'str->'],
proc { |stack, dictionary| Rpl::Lang::Core.to_string( stack, dictionary ) } ) 'String',
@dictionary.add( 'str->', '',
proc { |stack, dictionary| Rpl::Lang::Core.from_string( stack, dictionary ) } ) # alias
@dictionary.add( 'str→',
proc { |stack, dictionary| Rpl::Lang::Core.from_string( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.from_string( stack, dictionary ) } )
@dictionary.add( 'chr', @dictionary.add_word( ['chr'],
'String',
'',
proc { |stack, dictionary| Rpl::Lang::Core.chr( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.chr( stack, dictionary ) } )
@dictionary.add( 'num', @dictionary.add_word( ['num'],
'String',
'',
proc { |stack, dictionary| Rpl::Lang::Core.num( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.num( stack, dictionary ) } )
@dictionary.add( 'size', @dictionary.add_word( ['size'],
'String',
'',
proc { |stack, dictionary| Rpl::Lang::Core.size( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.size( stack, dictionary ) } )
@dictionary.add( 'pos', @dictionary.add_word( ['pos'],
'String',
'',
proc { |stack, dictionary| Rpl::Lang::Core.pos( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.pos( stack, dictionary ) } )
@dictionary.add( 'sub', @dictionary.add_word( ['sub'],
'String',
'',
proc { |stack, dictionary| Rpl::Lang::Core.sub( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.sub( stack, dictionary ) } )
@dictionary.add( 'rev', @dictionary.add_word( ['rev'],
'String',
'',
proc { |stack, dictionary| Rpl::Lang::Core.rev( stack, dictionary ) } ) # specific proc { |stack, dictionary| Rpl::Lang::Core.rev( stack, dictionary ) } ) # specific
@dictionary.add( 'split', @dictionary.add_word( ['split'],
'String',
'',
proc { |stack, dictionary| Rpl::Lang::Core.split( stack, dictionary ) } ) # specific proc { |stack, dictionary| Rpl::Lang::Core.split( stack, dictionary ) } ) # specific
# BRANCH # Branch
@dictionary.add( 'ift', @dictionary.add_word( ['ift'],
'Branch',
'',
proc { |stack, dictionary| Rpl::Lang::Core.ift( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.ift( stack, dictionary ) } )
@dictionary.add( 'ifte', @dictionary.add_word( ['ifte'],
'Branch',
'',
proc { |stack, dictionary| Rpl::Lang::Core.ifte( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.ifte( stack, dictionary ) } )
@dictionary.add( 'times', @dictionary.add_word( ['times'],
'Branch',
'',
proc { |stack, dictionary| Rpl::Lang::Core.times( stack, dictionary ) } ) # specific proc { |stack, dictionary| Rpl::Lang::Core.times( stack, dictionary ) } ) # specific
@dictionary.add( 'loop', @dictionary.add_word( ['loop'],
'Branch',
'',
proc { |stack, dictionary| Rpl::Lang::Core.loop( stack, dictionary ) } ) # specific proc { |stack, dictionary| Rpl::Lang::Core.loop( stack, dictionary ) } ) # specific
# @dictionary.add( 'if', # @dictionary.add_word( 'if',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # if <test-instruction> then <true-instructions> else <false-instructions> end # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # if <test-instruction> then <true-instructions> else <false-instructions> end
# @dictionary.add( 'then', # @dictionary.add_word( 'then',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with if # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with if
# @dictionary.add( 'else', # @dictionary.add_word( 'else',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with if # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with if
# @dictionary.add( 'end', # @dictionary.add_word( 'end',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with various branch instructions # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with various branch instructions
# @dictionary.add( 'start', # @dictionary.add_word( 'start',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # <start> <end> start <instructions> next|<step> step # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # <start> <end> start <instructions> next|<step> step
# @dictionary.add( 'for', # @dictionary.add_word( 'for',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # <start> <end> for <variable> <instructions> next|<step> step # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # <start> <end> for <variable> <instructions> next|<step> step
# @dictionary.add( 'next', # @dictionary.add_word( 'next',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with start and for # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with start and for
# @dictionary.add( 'step', # @dictionary.add_word( 'step',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with start and for # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with start and for
# @dictionary.add( 'do', # @dictionary.add_word( 'do',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # do <instructions> until <condition> end # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # do <instructions> until <condition> end
# @dictionary.add( 'until', # @dictionary.add_word( 'until',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with do # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with do
# @dictionary.add( 'while', # @dictionary.add_word( 'while',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # while <test-instruction> repeat <loop-instructions> end # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # while <test-instruction> repeat <loop-instructions> end
# @dictionary.add( 'repeat', # @dictionary.add_word( 'repeat',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with while # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # used with while
# STORE # Store
@dictionary.add( 'sto', @dictionary.add_word( ['▶', 'sto'],
'Store',
'',
proc { |stack, dictionary| Rpl::Lang::Core.sto( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.sto( stack, dictionary ) } )
@dictionary.add( '▶', @dictionary.add_word( ['rcl'],
proc { |stack, dictionary| Rpl::Lang::Core.sto( stack, dictionary ) } ) # alias 'Store',
@dictionary.add( 'rcl', '',
proc { |stack, dictionary| Rpl::Lang::Core.rcl( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.rcl( stack, dictionary ) } )
@dictionary.add( 'purge', @dictionary.add_word( ['purge'],
'Store',
'',
proc { |stack, dictionary| Rpl::Lang::Core.purge( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.purge( stack, dictionary ) } )
@dictionary.add( 'vars', @dictionary.add_word( ['vars'],
'Store',
'',
proc { |stack, dictionary| Rpl::Lang::Core.vars( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.vars( stack, dictionary ) } )
@dictionary.add( 'clusr', @dictionary.add_word( ['clusr'],
'Store',
'',
proc { |stack, dictionary| Rpl::Lang::Core.clusr( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.clusr( stack, dictionary ) } )
@dictionary.add( 'sto+', @dictionary.add_word( ['sto+'],
'Store',
'',
proc { |stack, dictionary| Rpl::Lang::Core.sto_add( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.sto_add( stack, dictionary ) } )
@dictionary.add( 'sto-', @dictionary.add_word( ['sto-'],
'Store',
'',
proc { |stack, dictionary| Rpl::Lang::Core.sto_subtract( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.sto_subtract( stack, dictionary ) } )
@dictionary.add( 'sto*', @dictionary.add_word( ['sto×', 'sto*'],
'Store',
'',
proc { |stack, dictionary| Rpl::Lang::Core.sto_multiply( stack, dictionary ) } ) # alias proc { |stack, dictionary| Rpl::Lang::Core.sto_multiply( stack, dictionary ) } ) # alias
@dictionary.add( 'sto×', @dictionary.add_word( ['sto÷', 'sto/'],
proc { |stack, dictionary| Rpl::Lang::Core.sto_multiply( stack, dictionary ) } ) 'Store',
@dictionary.add( 'sto/', '',
proc { |stack, dictionary| Rpl::Lang::Core.sto_divide( stack, dictionary ) } ) # alias proc { |stack, dictionary| Rpl::Lang::Core.sto_divide( stack, dictionary ) } ) # alias
@dictionary.add( 'sto÷', @dictionary.add_word( ['sneg'],
proc { |stack, dictionary| Rpl::Lang::Core.sto_divide( stack, dictionary ) } ) 'Store',
@dictionary.add( 'sneg', '',
proc { |stack, dictionary| Rpl::Lang::Core.sto_negate( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.sto_negate( stack, dictionary ) } )
@dictionary.add( 'sinv', @dictionary.add_word( ['sinv'],
'Store',
'',
proc { |stack, dictionary| Rpl::Lang::Core.sto_inverse( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.sto_inverse( stack, dictionary ) } )
# @dictionary.add( 'edit', # @dictionary.add_word( 'edit',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # edit a variable content # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # edit a variable content
@dictionary.add( 'lsto', @dictionary.add_word( ['↴', 'lsto'],
'Store',
'',
proc { |stack, dictionary| Rpl::Lang::Core.lsto( stack, dictionary ) } ) # store to local variable proc { |stack, dictionary| Rpl::Lang::Core.lsto( stack, dictionary ) } ) # store to local variable
@dictionary.add( '↴',
proc { |stack, dictionary| Rpl::Lang::Core.lsto( stack, dictionary ) } ) # alias
# PROGRAM # Program
@dictionary.add( 'eval', @dictionary.add_word( ['eval'],
'Program',
'',
proc { |stack, dictionary| Rpl::Lang::Core.eval( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.eval( stack, dictionary ) } )
# @dictionary.add( '->', # @dictionary.add_word( '->',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # load program local variables. ex: « → n m « 0 n m for i i + next » » # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # load program local variables. ex: « → n m « 0 n m for i i + next » »
# @dictionary.add( '→', # @dictionary.add_word( '→',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # alias # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # alias
# TRIG ON REALS AND COMPLEXES # Trig on reals and complexes
@dictionary.add( 'pi', @dictionary.add_word( ['𝛑', 'pi'],
'Trig on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.pi( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.pi( stack, dictionary ) } )
@dictionary.add( '𝛑', @dictionary.add_word( ['sin'],
proc { |stack, dictionary| Rpl::Lang::Core.pi( stack, dictionary ) } ) # alias 'Trig on reals and complexes',
@dictionary.add( 'sin', '',
proc { |stack, dictionary| Rpl::Lang::Core.sinus( stack, dictionary ) } ) # sinus proc { |stack, dictionary| Rpl::Lang::Core.sinus( stack, dictionary ) } ) # sinus
@dictionary.add( 'asin', @dictionary.add_word( ['asin'],
'Trig on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.arg_sinus( stack, dictionary ) } ) # arg sinus proc { |stack, dictionary| Rpl::Lang::Core.arg_sinus( stack, dictionary ) } ) # arg sinus
@dictionary.add( 'cos', @dictionary.add_word( ['cos'],
'Trig on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.cosinus( stack, dictionary ) } ) # cosinus proc { |stack, dictionary| Rpl::Lang::Core.cosinus( stack, dictionary ) } ) # cosinus
@dictionary.add( 'acos', @dictionary.add_word( ['acos'],
'Trig on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.arg_cosinus( stack, dictionary ) } ) # arg cosinus proc { |stack, dictionary| Rpl::Lang::Core.arg_cosinus( stack, dictionary ) } ) # arg cosinus
@dictionary.add( 'tan', @dictionary.add_word( ['tan'],
'Trig on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.tangent( stack, dictionary ) } ) # tangent proc { |stack, dictionary| Rpl::Lang::Core.tangent( stack, dictionary ) } ) # tangent
@dictionary.add( 'atan', @dictionary.add_word( ['atan'],
'Trig on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.arg_tangent( stack, dictionary ) } ) # arg tangent proc { |stack, dictionary| Rpl::Lang::Core.arg_tangent( stack, dictionary ) } ) # arg tangent
@dictionary.add( 'd->r', @dictionary.add_word( ['d→r', 'd->r'],
'Trig on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.degrees_to_radians( stack, dictionary ) } ) # convert degrees to radians proc { |stack, dictionary| Rpl::Lang::Core.degrees_to_radians( stack, dictionary ) } ) # convert degrees to radians
@dictionary.add( 'd→r', @dictionary.add_word( ['r→d', 'r->d'],
proc { |stack, dictionary| Rpl::Lang::Core.degrees_to_radians( stack, dictionary ) } ) # alias 'Trig on reals and complexes',
@dictionary.add( 'r->d', '',
proc { |stack, dictionary| Rpl::Lang::Core.radians_to_degrees( stack, dictionary ) } ) # convert radians to degrees proc { |stack, dictionary| Rpl::Lang::Core.radians_to_degrees( stack, dictionary ) } ) # convert radians to degrees
@dictionary.add( 'r→d',
proc { |stack, dictionary| Rpl::Lang::Core.radians_to_degrees( stack, dictionary ) } ) # alias
# LOGS ON REALS AND COMPLEXES # Logs on reals and complexes
@dictionary.add( 'e', @dictionary.add_word( ['ℇ', 'e'],
'Logs on reals and complexes',
'',
proc { |stack, dictionary| Rpl::Lang::Core.e( stack, dictionary ) } ) # alias proc { |stack, dictionary| Rpl::Lang::Core.e( stack, dictionary ) } ) # alias
@dictionary.add( 'ℇ', # @dictionary.add_word( 'ln',
proc { |stack, dictionary| Rpl::Lang::Core.e( stack, dictionary ) } )
# @dictionary.add( 'ln',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # logarithm base e # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # logarithm base e
# @dictionary.add( 'lnp1', # @dictionary.add_word( 'lnp1',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # ln(1+x) which is useful when x is close to 0 # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # ln(1+x) which is useful when x is close to 0
# @dictionary.add( 'exp', # @dictionary.add_word( 'exp',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # exponential # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # exponential
# @dictionary.add( 'expm', # @dictionary.add_word( 'expm',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # exp(x)-1 which is useful when x is close to 0 # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # exp(x)-1 which is useful when x is close to 0
# @dictionary.add( 'log10', # @dictionary.add_word( 'log10',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # logarithm base 10 # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # logarithm base 10
# @dictionary.add( 'alog10', # @dictionary.add_word( 'alog10',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # exponential base 10 # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # exponential base 10
# @dictionary.add( 'log2', # @dictionary.add_word( 'log2',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # logarithm base 2 # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # logarithm base 2
# @dictionary.add( 'alog2', # @dictionary.add_word( 'alog2',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # exponential base 2 # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # exponential base 2
# @dictionary.add( 'sinh', # @dictionary.add_word( 'sinh',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # hyperbolic sine # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # hyperbolic sine
# @dictionary.add( 'asinh', # @dictionary.add_word( 'asinh',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # inverse hyperbolic sine # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # inverse hyperbolic sine
# @dictionary.add( 'cosh', # @dictionary.add_word( 'cosh',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # hyperbolic cosine # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # hyperbolic cosine
# @dictionary.add( 'acosh', # @dictionary.add_word( 'acosh',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # inverse hyperbolic cosine # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # inverse hyperbolic cosine
# @dictionary.add( 'tanh', # @dictionary.add_word( 'tanh',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # hyperbolic tangent # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # hyperbolic tangent
# @dictionary.add( 'atanh', # @dictionary.add_word( 'atanh',
# proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # inverse hyperbolic tangent # proc { |stack, dictionary| Rpl::Lang::Core.__todo( stack, dictionary ) } ) # inverse hyperbolic tangent
# TIME AND DATE # Time and date
@dictionary.add( 'time', @dictionary.add_word( ['time'],
'Time and date',
'',
proc { |stack, dictionary| Rpl::Lang::Core.time( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.time( stack, dictionary ) } )
@dictionary.add( 'date', @dictionary.add_word( ['date'],
'Time and date',
'',
proc { |stack, dictionary| Rpl::Lang::Core.date( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.date( stack, dictionary ) } )
@dictionary.add( 'ticks', @dictionary.add_word( ['ticks'],
'Time and date',
'',
proc { |stack, dictionary| Rpl::Lang::Core.ticks( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.ticks( stack, dictionary ) } )
# Rpl.rb specifics # Rpl.rb specifics
# LISTS # Lists
@dictionary.add( '->list', @dictionary.add_word( ['→list', '->list'],
'Lists',
'',
proc { |stack, dictionary| Rpl::Lang::Core.to_list( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.to_list( stack, dictionary ) } )
@dictionary.add( '→list', @dictionary.add_word( ['list→', 'list->'],
proc { |stack, dictionary| Rpl::Lang::Core.to_list( stack, dictionary ) } ) # alias 'Lists',
@dictionary.add( 'list->', '',
proc { |stack, dictionary| Rpl::Lang::Core.unpack_list( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.unpack_list( stack, dictionary ) } )
@dictionary.add( 'list→',
proc { |stack, dictionary| Rpl::Lang::Core.unpack_list( stack, dictionary ) } ) # alias
# FILESYSTEM # Filesystem
@dictionary.add( 'fread', @dictionary.add_word( ['fread'],
'Filesystem',
'',
proc { |stack, dictionary| Rpl::Lang::Core.fread( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.fread( stack, dictionary ) } )
@dictionary.add( 'feval', @dictionary.add_word( ['feval'],
'Filesystem',
'',
proc { |stack, dictionary| Rpl::Lang::Core.feval( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.feval( stack, dictionary ) } )
@dictionary.add( 'fwrite', @dictionary.add_word( ['fwrite'],
'Filesystem',
'',
proc { |stack, dictionary| Rpl::Lang::Core.fwrite( stack, dictionary ) } ) proc { |stack, dictionary| Rpl::Lang::Core.fwrite( stack, dictionary ) } )
# GRAPHICS # Graphics
end end
end end
end end

View file

@ -24,6 +24,16 @@ module Rpl
[stack, dictionary] [stack, dictionary]
end end
def help( stack, dictionary )
stack, args = Rpl::Lang.stack_extract( stack, [%i[name]] )
word = dictionary.words[ args[0][:value] ]
stack << { type: :string,
value: "#{args[0][:value]}: #{word.nil? ? 'not a core word' : word[:help]}" }
[stack, dictionary]
end
end end
end end
end end

View file

@ -3,7 +3,8 @@
module Rpl module Rpl
module Lang module Lang
class Dictionary class Dictionary
attr_reader :vars, attr_reader :words,
:vars,
:local_vars_layers :local_vars_layers
def initialize def initialize
@ -12,8 +13,12 @@ module Rpl
@local_vars_layers = [] @local_vars_layers = []
end end
def add( name, implementation ) def add_word( names, category, help, implementation )
@words[ name ] = implementation names.each do |name|
@words[ name ] = { category: category,
help: help,
implementation: implementation }
end
end end
def add_var( name, implementation ) def add_var( name, implementation )
@ -65,7 +70,7 @@ module Rpl
word ||= @vars[ name ] word ||= @vars[ name ]
# or is it a core word # or is it a core word
word ||= @words[ name ] word ||= @words[ name ].nil? ? nil : @words[ name ][:implementation]
word word
end end