functions examples are added
This commit is contained in:
parent
ffb4e2d3e5
commit
7d368b805b
|
@ -0,0 +1 @@
|
||||||
|
w "The ASCII code of ""a"" is ",$ascii("a"),".",!
|
|
@ -0,0 +1,3 @@
|
||||||
|
w "Alphabet: ",!
|
||||||
|
f i=97:1:122 w $char(i)
|
||||||
|
w !
|
|
@ -0,0 +1,26 @@
|
||||||
|
s gtree(1)="Oliver"
|
||||||
|
s gtree(1,1)="James"
|
||||||
|
s gtree(1,1,1)="Harry"
|
||||||
|
s gtree(1,1,2)="Emily"
|
||||||
|
s gtree(1,2)="Amelia"
|
||||||
|
s gtree(1,2,1)="Thomas"
|
||||||
|
s gtree(1,2,2)="Jessica"
|
||||||
|
; ...
|
||||||
|
s gtree(1,1,1,1,1)="Robert"
|
||||||
|
|
||||||
|
w "Genealogical tree:",!
|
||||||
|
|
||||||
|
zwrite gtree
|
||||||
|
|
||||||
|
; obtain data about a particular node
|
||||||
|
; 0, the node does not exist
|
||||||
|
; 1, the node exists, has no descendant
|
||||||
|
; 10, the node exists, has no data, has descendant
|
||||||
|
; 11, the node exists, has data, has descendant
|
||||||
|
|
||||||
|
w !,"Data about a few nodes: ",!
|
||||||
|
|
||||||
|
w "$d(gtree(""foo"")) is ",$d(gtree("foo")),!
|
||||||
|
w "$d(gtree(1,1,1,1,1)) is ",$d(gtree(1,1,1,1,1)),!
|
||||||
|
w "$d(gtree(1,1,1,1)) is ",$d(gtree(1,1,1,1)),!
|
||||||
|
w "$d(gtree(1)) is ",$d(gtree(1)),!
|
|
@ -0,0 +1,3 @@
|
||||||
|
s string="Hello world!"
|
||||||
|
w "Original string: ",string,!
|
||||||
|
w "Substring: ",$extract(string,1,5),!
|
|
@ -1,57 +0,0 @@
|
||||||
|
|
||||||
; global array as a tree
|
|
||||||
|
|
||||||
w "Genealogical tree:",!
|
|
||||||
|
|
||||||
; create global records
|
|
||||||
|
|
||||||
s ^gtree(0)="Oliver"
|
|
||||||
s ^gtree(0,0)="Jack"
|
|
||||||
s ^gtree(0,1)="Amelia"
|
|
||||||
s ^gtree(0,0,0)="Harry"
|
|
||||||
s ^gtree(0,0,1)="Emily"
|
|
||||||
s ^gtree(0,1,0)="Thomas"
|
|
||||||
s ^gtree(0,1,1)="Jessica"
|
|
||||||
s ^gtree(0,0,0,0)="Michael"
|
|
||||||
s ^gtree(0,0,0,1)="Olivia"
|
|
||||||
s ^gtree(0,0,1,0)="Robert"
|
|
||||||
s ^gtree(0,0,1,1)="Mary"
|
|
||||||
s ^gtree(0,1,0,0)="George"
|
|
||||||
s ^gtree(0,1,0,1)="Susan"
|
|
||||||
s ^gtree(0,1,1,0)="Charles"
|
|
||||||
s ^gtree(0,1,1,1)="Elizabeth"
|
|
||||||
; ...
|
|
||||||
s ^gtree(0,0,0,0,0,0)="Thomas"
|
|
||||||
|
|
||||||
; TODO: traverse the tree and display information
|
|
||||||
; ...
|
|
||||||
|
|
||||||
; retrieve a global record
|
|
||||||
|
|
||||||
w "^gtree(0,1,1) is ",^gtree(0,1,1),!
|
|
||||||
|
|
||||||
; obtain data about a particular node
|
|
||||||
; 0, the node does not exist
|
|
||||||
; 1, the node exists, has no descendant
|
|
||||||
; 10, the node exists, has no data, has descendant
|
|
||||||
; 11, the node exists, has data, has descendant
|
|
||||||
|
|
||||||
w "$data(^gtree(0,2)) is ",$data(^gtree(0,3)),!
|
|
||||||
w "$data(^gtree(0,1,1,1)) is ",$data(^gtree(0,1,1,1)),!
|
|
||||||
w "$data(^gtree(0,0,0,0,0)) is ",$data(^gtree(0,0,0,0,0)),!
|
|
||||||
w "$data(^gtree(0)) is ",$data(^gtree(0)),!
|
|
||||||
|
|
||||||
; remove the global array
|
|
||||||
; 0, the node does not exist
|
|
||||||
; 0, the node does not exist
|
|
||||||
; 0, the node does not exist
|
|
||||||
; 0, the node does not exist
|
|
||||||
|
|
||||||
w !,"Removing tree...",!
|
|
||||||
|
|
||||||
k ^gtree
|
|
||||||
|
|
||||||
w "$data(^gtree(0,2)) is ",$data(^gtree(0,3)),!
|
|
||||||
w "$data(^gtree(0,1,1,1)) is ",$data(^gtree(0,1,1,1)),!
|
|
||||||
w "$data(^gtree(0,0,0,0,0)) is ",$data(^gtree(0,0,0,0,0)),!
|
|
||||||
w "$data(^gtree(0)) is ",$data(^gtree(0)),!
|
|
47
README.md
47
README.md
|
@ -157,7 +157,37 @@ Then run the example:
|
||||||
|
|
||||||
## 2. Functions
|
## 2. Functions
|
||||||
|
|
||||||
> TODO.
|
### [`Ascii.m`](https://github.com/programarivm/mumps-examples/blob/master/02-functions/Ascii.m)
|
||||||
|
|
||||||
|
The ASCII code of "a" is 97.
|
||||||
|
|
||||||
|
### [`Char.m`](https://github.com/programarivm/mumps-examples/blob/master/02-functions/Char.m)
|
||||||
|
|
||||||
|
Alphabet:
|
||||||
|
abcdefghijklmnopqrstuvwxyz
|
||||||
|
|
||||||
|
### [`Data.m`](https://github.com/programarivm/mumps-examples/blob/master/02-functions/Data.m)
|
||||||
|
|
||||||
|
Genealogical tree:
|
||||||
|
gtree(1)="Oliver"
|
||||||
|
gtree(1,1)="James"
|
||||||
|
gtree(1,1,1)="Harry"
|
||||||
|
gtree(1,1,1,1,1)="Robert"
|
||||||
|
gtree(1,1,2)="Emily"
|
||||||
|
gtree(1,2)="Amelia"
|
||||||
|
gtree(1,2,1)="Thomas"
|
||||||
|
gtree(1,2,2)="Jessica"
|
||||||
|
|
||||||
|
Data about a few nodes:
|
||||||
|
$d(gtree("foo")) is 0
|
||||||
|
$d(gtree(1,1,1,1,1)) is 1
|
||||||
|
$d(gtree(1,1,1,1)) is 10
|
||||||
|
$d(gtree(1)) is 11
|
||||||
|
|
||||||
|
### [`Extract.m`](https://github.com/programarivm/mumps-examples/blob/master/02-functions/Extract.m)
|
||||||
|
|
||||||
|
Original string: Hello world!
|
||||||
|
Substring: Hello
|
||||||
|
|
||||||
## 3. Utility Routines
|
## 3. Utility Routines
|
||||||
|
|
||||||
|
@ -196,21 +226,6 @@ Then run the example:
|
||||||
|
|
||||||
## 6. Databases
|
## 6. Databases
|
||||||
|
|
||||||
### [`GenealogicalTree.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/GenealogicalTree.m)
|
|
||||||
|
|
||||||
Genealogical tree:
|
|
||||||
^gtree(0,1,1) is Jessica
|
|
||||||
$data(^gtree(0,2)) is 0
|
|
||||||
$data(^gtree(0,1,1,1)) is 1
|
|
||||||
$data(^gtree(0,0,0,0,0)) is 10
|
|
||||||
$data(^gtree(0)) is 11
|
|
||||||
|
|
||||||
Removing tree...
|
|
||||||
$data(^gtree(0,2)) is 0
|
|
||||||
$data(^gtree(0,1,1,1)) is 0
|
|
||||||
$data(^gtree(0,0,0,0,0)) is 0
|
|
||||||
$data(^gtree(0)) is 0
|
|
||||||
|
|
||||||
### [`basic-sql-crud/Main.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-crud/Main.m)
|
### [`basic-sql-crud/Main.m`](https://github.com/programarivm/mumps-examples/blob/master/06-databases/basic-sql-crud/Main.m)
|
||||||
|
|
||||||
User successfully created!
|
User successfully created!
|
||||||
|
|
Loading…
Reference in New Issue