Vocabulary/tildem

From J Wiki
Jump to: navigation, search

>> <<   Back to: Vocabulary Thru to: Dictionary

m~ Evoke Adverb

Rank -- depends on the rank of u -- WHY IS THIS IMPORTANT?



(m~) is the value of the name (m)

m must be a noun or a phrase that evaluates to a noun, and the resulting noun must be a defined name

   name =: 'value of name'
   m =: 'name'

   m~
value of name
   ('na','me')~
value of name

When m is the name of a noun, m~ is the same as (". m) (which executes the phrase m to produce the noun result). But when m is not a noun, only m~ will work OK

   ". m          NB. ".m works OK when value of name is a noun
value of name
   name =: +     NB. name has a value, but it is NOT a noun
   m~            NB. m~ still works
+
   ]z =: ". m    NB. but ".m evaluates to ''

   assert z -: ''

Common uses

1. Pass a verb (by name) as the x-argument to a 2nd verb: parse

   NB. Parse string: y and call the callback verb named (x)
   NB. with the result as its y-argument.

   parse=: 4 : 0
result=. |.y   NB. (sample processing applied to y)
x~ result
)

Names used as callbacks in GUI code are often passed this way.
Alternatively rewrite parse as an adverb (or a conjunction).

Here (m~) serves as an alternative to using Evoke Gerund (m`:6) with the gerund (m).


Details

1. (m~) is peculiar when (m) is one of the special local names (x y u v m n) in an explicit definition. When those names are used normally in a sentence, they are always replaced by their value, and thus the special name never appears on the execution stack. When the special name is the (m) in (m~), it is not replaced by its value, and thus the special name does appear on the execution stack. This usually results in a value error.


Related Primitives

Evoke Gerund (`:6), Do (". y)