You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+170Lines changed: 170 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -404,4 +404,174 @@ The *cut()* function takes a string, a starting index, and ending index and retu
404
404
"abcdefg"
405
405
>> cut(`abcdefgh`, 0, -4)
406
406
"abcd"
407
+
```
408
+
409
+
###find(string, substr)
410
+
411
+
The *find()* function takes a string and substr argument(a string smaller than the first argument), and checks if that substr is in the first argument. If it is, it returns the starting index for it. If it's not in the string, it returns -1.
412
+
413
+
```
414
+
>> find(`appleswafflesavocadoes`, `waffles`)
415
+
6
416
+
>> find(`appleswafflesavocadoes`, `apples`)
417
+
0
418
+
>> find(`appleswafflesavocadoes`, `fruits`)
419
+
-1
420
+
```
421
+
422
+
###~(string, regex)
423
+
424
+
The *~()* function takes a string argument and a string that represents a regex pattern and perfroms a regex match. It returns true or false if the string is a match or not.
425
+
426
+
```
427
+
>> ~(`hello world!`, `.*`)
428
+
true
429
+
>> ~(`hello world!`, `.`)
430
+
true
431
+
>> ~(`hello world!`, `^.$`)
432
+
false
433
+
>> ~(`hello world!`, `^[a-z !]+$`)
434
+
true
435
+
>> ~(`hello world!`, `^[a-z]+$`)
436
+
false
437
+
438
+
```
439
+
440
+
##List Functions
441
+
442
+
RoyalScript, unlike other functional languages employes the use of mutablee data. One feature of mutable data are lists. Lists are ordered, indexable, collections of multiple types of values.
443
+
444
+
However, the language allows you to use lists in an immutable fashion as well, which will be explained below.
445
+
446
+
###list(...)
447
+
448
+
the *list()* function takes an arbitrary number of arguments and returns a list of those arguments. If no arguments are specified, it returns an empty list. Lists can also be nested
449
+
450
+
```
451
+
>> list(1, 2, 3)
452
+
[1,2,3]
453
+
>> list(1, 2, +(3, 4))
454
+
[1,2,7]
455
+
>> list(1, true, +(3, 4))
456
+
[1,true,7]
457
+
>> list(list(3, list()))
458
+
[[3,[]]]
459
+
```
460
+
461
+
###range(start, end)
462
+
463
+
The *range()* function creates a list of numbers that start at some value and end at some high value. The start number must be lower than the end number.
464
+
465
+
```
466
+
>> range(0, 5)
467
+
[0,1,2,3,4]
468
+
>> range(0, 10)
469
+
[0,1,2,3,4,5,6,7,8,9]
470
+
>> range(0, 0)
471
+
[]
472
+
```
473
+
Ranges can also be used to check if a number is in the indexes of some list.
474
+
475
+
```
476
+
>> in(1, range(0, 5))
477
+
true
478
+
```
479
+
Note though, the *in()* function checkes the keys of a list, not it's values. To find if a value is in a list, use the *find()* function.
480
+
481
+
###make(arg1, amount)
482
+
483
+
The *make()* function takes one argument and a number, to return a list containing the first argument repeated some specified number of times. This function must have 2 arguments otherwise an error is raised.
Argument Error: Got improper arguments but expected 2.
494
+
```
495
+
496
+
###rep(list)
497
+
498
+
The *rep()* function takes a list as an argument and returns a copy of that list. This means that changes to this copy wont effect the previous list. Here is a little example for this behavior.
499
+
500
+
```
501
+
>> =(a, list(1, 2,3))
502
+
undefined
503
+
>> =(b, rep(a))
504
+
undefined
505
+
>> do(a)
506
+
[1,2,3]
507
+
>> do(b)
508
+
[1,2,3]
509
+
>> put(b, 1)
510
+
4
511
+
>> do(b)
512
+
[1,1,2,3]
513
+
>> do(a)
514
+
[1,2,3]
515
+
```
516
+
517
+
The rep function is useful for using lists in an immutable fashion. There are also other list functions that return a new copy of the list.
518
+
519
+
###len(list)
520
+
521
+
Returns the amount of items in the list.
522
+
523
+
###cut(list, start, end)
524
+
525
+
Identical functionality to *cut()* being used on strings, returns a smaller list of the items between the specified start and end index.
526
+
527
+
###get(list, index)
528
+
529
+
The *get()* function, much like for strings, takes a list and index arguments, and returns the item in the list present at that index.
530
+
531
+
```
532
+
>> =(a, list(1, 2,3))
533
+
undefined
534
+
>> get(a, 1)
535
+
2
536
+
>> get(a, 0)
537
+
1
538
+
>> get(a, 6)
539
+
undefined
540
+
```
541
+
542
+
###set(list, index, value)
543
+
544
+
The *set()* function takes a list, a number index, and a value to set the index of the list equal to the value. Setting the value of an index beyond the length of the list still works, and the values in between will be set to *null*.
545
+
546
+
```
547
+
>> =(e, range(0, 5))
548
+
undefined
549
+
>> set(e, 2, 60)
550
+
60
551
+
>> do(e)
552
+
[0,1,60,3,4]
553
+
>> set(e, 10, 60)
554
+
60
555
+
>> do(e)
556
+
[0,1,60,3,4,null,null,null,null,null,60]
557
+
```
558
+
559
+
**warning**: To prevent unintended behavior, *set()*, and a few other functions in RoyalScript are considered non-nestable. This means since they aren't meant to evaluate to something, you cannot use them as arguments to other functions, such as:
560
+
561
+
```
562
+
>> str(set(e, 10, 60))
563
+
SyntaxError: missing ) after argument list
564
+
```
565
+
566
+
###append(list, arg1)
567
+
568
+
The *append()* function takes a list and another argument and places that argument at the end of the list. It, like set is a non-nestable function
0 commit comments