4 ms·
Interpreter for AsYetUnnamedProgrammingLanguage by MichaelSpeer v0.-1 > > declare . Products . :name PHRASE . :price MONEY'USD . ; > create
by knome 19y ago
Interpreter for AsYetUnnamedProgrammingLanguage by
MichaelSpeer v0.-1
>
> declare
. Products
. :name PHRASE
. :price MONEY'USD
. ;
> create Products [ :name , :price ] =
. [ "DVD Player" , 20'USD ] ,
. [ "VCR" , 15.5'USD ] ,
. [ "DVD" , 7'USD ] ,
. [ "VCR Tape" , 4'USD ]
. ;
> Products ;
[ 1 , 2 , 3 , 4 ]
> Products:id ;
[ 1 , 2 , 3 , 4 ]
> Products[ :id , :name ] ;
[ 1 , "DVD Player" ]
[ 2 , "VCR" ]
[ 3 , "DVD" ]
[ 4 , "VCR Tape" ]
> Products( :price < 5'USD )[ :name ];
[ "VCR Tape" ]
> Products( :price > 10'USD ):name ;
[ "DVD Player" , "VCR" ]
> Products( :price > 10'USD )[ :name ] ;
[ "DVD Player" ]
[ "VCR" ]
> Products( asc :name ):name ;
[ "DVD" , "DVD Player" , "VCR" , "VCR Tape" ]
> declare
. Categories
. :name PHRASE
. :sub-products -> Products:category single
. ;
> create Categories [ :name , :sub-products ] =
. [ "Video Players" , Products( :name in [ "DVD Player" ,
"VCR" ] ) ]
. ;
> Products:category:name ;
[ "Video Players" ]
> Products[ :category:name ] ;
[]
[ "Video Players" ]
[]
[ "Video Players" ]
> Products( :category ):name ; -- returns products that
have a category
[ "DVD Player" , "VCR" ]
> Products( not :category ):name ; -- returns products
lacking a category
[ "DVD" , "VCR Tape" ]
> Products( :id != 3 && :id != 4 )[ :name ] ;
[ "DVD Player" ]
[ "VCR" ]
> create Categories [ :name , :sub-products ] =
. [ "Blank Media" , Products( not :category ) ]
. ;
> Products( :category( :sub-products( :name == "DVD" ) )
):name ;
[ "DVD" , "VCR Tape" ]
> alter Products( :category( :name == "Media" ) )[ :price ]
= [ :price += 1'USD ] ;
> declare Categories:recommended ->
:sub-products:recommended-by ;
> alter Categories( :name == "Media" )[ :recommended ] = [
:sub-products( :name == "DVD" ) ] ;