From 67a8b6fcd9ff8e00bb2af9e204a3103c6d6a62e9 Mon Sep 17 00:00:00 2001 From: brianharvey Date: Sat, 28 Nov 2020 16:44:33 -0800 Subject: [PATCH] more efficient libraries taking advantage of js primitives and also converting sentences to and from lists. --- libraries/list-utilities.xml | 2 +- libraries/word-sentence.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/list-utilities.xml b/libraries/list-utilities.xml index 2009b5be..db098c5a 100644 --- a/libraries/list-utilities.xml +++ b/libraries/list-utilities.xml @@ -1 +1 @@ -Reports a new list containing the items of the input list, but in the opposite order.
ca:capgira _ 1inputresult
Reports a new list whose items are the same as in the input list, except that if two or more equal items appear in the input list, only the last one is kept in the result.
ca:elimina els duplicats de _ 1
Reports a sorted version of the list in its first input slot, using the comparison function in the second input slot. For a list of numbers, using < as the comparison function will sort from low to high; using > will sort from high to low.
ca:ordena _ segons criteri _ copy of datasplitmerge11#1#2
The second input is an "association list," a list of two-item lists. Each of those smaller lists has a "key" as its first item and a "value" as its second. ASSOC reports the first key-value pair in the association list whose key matches the first input.
ca:associació _ _ 11
This block carries out the given script for each item of the given list, like the primitive FOR EACH. What's different is that it provides the # variable, which will contain the item number in the list of each item in turn, 1 while processing item 1, and so on.
ca:_ per cada _ de _ _
Takes as input a function of N inputs and N lists. The function is called with item 1 of all the lists as its inputs, with item 2 of all the lists as its inputs, and so on. (The lists should all be the same length.)
ZIP takes any number of lists as inputs. The lists should all be the same length. ZIP reports a list of lists in which the first item is a list of all the first items, the second item is a list of all the second items, etc. Viewing the inputs as the rows of a matrix, ZIP reports its transpose.
1
The identity function reports its input.
\ No newline at end of file +Reports a new list containing the items of the input list, but in the opposite order.
ca:capgira _ 1inputresult
Reports a new list whose items are the same as in the input list, except that if two or more equal items appear in the input list, only the last one is kept in the result.
ca:elimina els duplicats de _ 1
Reports a sorted version of the list in its first input slot, using the comparison function in the second input slot. For a list of numbers, using < as the comparison function will sort from low to high; using > will sort from high to low.
ca:ordena _ segons criteri _ copy of datasplitmerge11#1#2
The second input is an "association list," a list of two-item lists. Each of those smaller lists has a "key" as its first item and a "value" as its second. ASSOC reports the first key-value pair in the association list whose key matches the first input.
ca:associació _ _ 11
This block carries out the given script for each item of the given list, like the primitive FOR EACH. What's different is that it provides the # variable, which will contain the item number in the list of each item in turn, 1 while processing item 1, and so on.
ca:_ per cada _ de _ _
Takes as input a function of N inputs and N lists. The function is called with item 1 of all the lists as its inputs, with item 2 of all the lists as its inputs, and so on. (The lists should all be the same length.)
ZIP takes any number of lists as inputs. The lists should all be the same length. ZIP reports a list of lists in which the first item is a list of all the first items, the second item is a list of all the second items, etc. Viewing the inputs as the rows of a matrix, ZIP reports its transpose.
position11
The identity function reports its input.
\ No newline at end of file diff --git a/libraries/word-sentence.xml b/libraries/word-sentence.xml index aa5290b2..19c1f47d 100644 --- a/libraries/word-sentence.xml +++ b/libraries/word-sentence.xml @@ -1 +1 @@ -Takes a text string as input, and reports a new text string containing all but the first character of the input.
pt:_ sem o primeiro caractere resulti2
Takes a text string as input, divides it into words treating one or more spaces as a word separator (only spaces count; punctuation is part of the word) and reports a text string containing all but the first word, with one space between words and no spaces at the beginning or end. (Note: consider using SENTENCE->LIST and processing the resulting list instead of doing recursion on sentences in text string form. List operations are faster.)
pt:_ sem a primeira palavra 0
Takes a text string as input, and reports a new text string containing all but the last letter of the input.
pt:_ sem o último caractere resulti1
Takes a text string as input, divides it into words treating one or more spaces as a word separator (only spaces count; punctuation is part of the word) and reports a text string containing all but the last word, with one space between words and no spaces at the beginning or end. (Note: consider using SENTENCE->LIST and processing the resulting list instead of doing recursion on sentences in text string form. List operations are faster.)
pt:_ sem a última palavra 01 1 11 1
Takes a text string as input, divides it into words treating one or more spaces as a word separator (only spaces count; punctuation is part of the word) and reports a text string containing only the first word, with no spaces before or after it.
pt:a primeira palavra de _
Takes a text string as input, and reports the last character in the string.
pt:o último caractere de _ 0
Takes a text string as input, divides it into words treating one or more spaces as a word separator (only spaces count; punctuation is part of the word) and reports a text string containing only the last word of the input, with no spaces before or after it.
pt:a última palavra de _ index01 1
Takes a text string as input, and reports TRUE if the string has no characters in it of any kind, otherwise false.
pt:a palavra _ está vazia 0
Takes a text string as input, and reports TRUE if the input contains no characters other than spaces (therefore, no words when the string is considered as a sentence), otherwise FALSE.
pt:a frase _ está vazia index10
Like JOIN, takes any number of words (text strings) and reports a sentence with its inputs concatenated, but inserts a blank space between the inputs. Consider using SENTENCE (Lists palette) instead.
de:füge Wörter zusammen _ ca:uneix les paraules _ es:unir las palabras _ fr:fusionne les mots _ pt:uma frase com as palavras _ 1121
Takes a sentence in list form and reports the sentence as a text string.
de:Liste $arrowRight Satz _ ca:llista $arrowRight frase _ es:lista $arrowRight frase _ fr:liste $arrowRight phrase _ pt:uma frase com as palavras em _
Takes a sentence in text string form and reports the sentence as a list of its words.
de:Satz $arrowRight Liste _ ca:frase $arrowRight llista _ es:frase $arrowRight lista _ fr:phrase $arrowRight liste _ pt:uma lista com as palavras da frase _
report a list in which each item is one letter from the input word
de:Wort $arrowRight Liste _ ca:paraula $arrowRight llista _ es:palabra $arrowRight lista _ fr:mot $arrowRight liste _ pt:uma lista com os caracteres da palavra _
join all the items of the input list into a single word, and report it
de:Liste $arrowRight Wort _ ca:llista $arrowRight paraula _ es:lista $arrowRight palabra _ fr:liste $arrowRight mot _ pt:uma palavra com os caracteres em _
SENTENCE is the main constructor for sentences, represented as lists of words. It takes zero or more inputs, each of which can be either a list or a text string. If a list, the input is assumed to be a list of words. If a text string, it is converted to a list of words using SENTENCE→LIST. Then all the lists of words are appended to form a new list of words. If the inputs are lists of lists rather than lists of words, SENTENCE, like APPEND, does only one level of flattening, reporting a list of all the items of all the input lists.
pt:lança o erro _
Takes a (possibly deep) list as input, and reports a human-readable text form of the list (namely, Lisp notation).
( )
\ No newline at end of file +Takes a text string as input, and reports a new text string containing all but the first character of the input.
pt:_ sem o primeiro caractere strreturn str.slice(1);All but first of empty word.
Takes a text string as input, divides it into words treating one or more spaces as a word separator (only spaces count; punctuation is part of the word) and reports a text string containing all but the first word, with one space between words and no spaces at the beginning or end. (Note: consider using SENTENCE➞LIST and processing the resulting list instead of doing recursion on sentences in text string form. List operations are faster.)
pt:_ sem a primeira palavra All but first of empty sentence.
Takes a text string as input, and reports a new text string containing all but the last letter of the input.
pt:_ sem o último caractere strreturn str.slice(0,-1);All but last of empty word.
Takes a text string as input, divides it into words treating one or more spaces as a word separator (only spaces count; punctuation is part of the word) and reports a text string containing all but the last word, with one space between words and no spaces at the beginning or end. (Note: consider using SENTENCE->LIST and processing the resulting list instead of doing recursion on sentences in text string form. List operations are faster.)
pt:_ sem a última palavra arrreturn new List(arr.asArray().slice(0,-1));All but last of empty sentence. 1 11 1
Takes a text string as input, divides it into words treating one or more spaces as a word separator (only spaces count; punctuation is part of the word) and reports a text string containing only the first word, with no spaces before or after it.
pt:a primeira palavra de _
Takes a text string as input, and reports the last character in the string.
pt:o último caractere de _ 0
Takes a text string as input, divides it into words treating one or more spaces as a word separator (only spaces count; punctuation is part of the word) and reports a text string containing only the last word of the input, with no spaces before or after it.
pt:a última palavra de _ Last of empty sentence.1 1
Takes a text string as input, and reports TRUE if the string has no characters in it of any kind, otherwise false.
pt:a palavra _ está vazia 0
Takes a text string as input, and reports TRUE if the input contains no characters other than spaces (therefore, no words when the string is considered as a sentence), otherwise FALSE.
pt:a frase _ está vazia
Like JOIN, takes any number of words (text strings) and reports a sentence with its inputs concatenated, but inserts a blank space between the inputs. Consider using SENTENCE (Lists palette) instead.
de:füge Wörter zusammen _ ca:uneix les paraules _ es:unir las palabras _ fr:fusionne les mots _ pt:uma frase com as palavras _ firstbffirst111bf 121
Takes a sentence in list form and reports the sentence as a text string.
de:Liste $arrowRight Satz _ ca:llista $arrowRight frase _ es:lista $arrowRight frase _ fr:liste $arrowRight phrase _ pt:uma frase com as palavras em _
Takes a sentence in text string form and reports the sentence as a list of its words.
de:Satz $arrowRight Liste _ ca:frase $arrowRight llista _ es:frase $arrowRight lista _ fr:phrase $arrowRight liste _ pt:uma lista com as palavras da frase _
report a list in which each item is one letter from the input word
de:Wort $arrowRight Liste _ ca:paraula $arrowRight llista _ es:palabra $arrowRight lista _ fr:mot $arrowRight liste _ pt:uma lista com os caracteres da palavra _
join all the items of the input list into a single word, and report it
de:Liste $arrowRight Wort _ ca:llista $arrowRight paraula _ es:lista $arrowRight palabra _ fr:liste $arrowRight mot _ pt:uma palavra com os caracteres em _
SENTENCE is the main constructor for sentences, represented as lists of words. It takes zero or more inputs, each of which can be either a list or a text string. If a list, the input is assumed to be a list of words. If a text string, it is converted to a list of words using SENTENCE→LIST. Then all the lists of words are appended to form a new list of words. If the inputs are lists of lists rather than lists of words, SENTENCE, like APPEND, does only one level of flattening, reporting a list of all the items of all the input lists.
pt:lança o erro _
Takes a (possibly deep) list as input, and reports a human-readable text form of the list (namely, Lisp notation).
( )
Helper function for word/sentence library. Reports its first input, unless that input is empty, in which case it gives its second input as an error message.
Takes a text string as input, and reports the first character in the string.
pt:a primeira palavra de _
\ No newline at end of file