Skip to content

Commit

Permalink
spin words example added
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardo-imadeira committed Feb 23, 2024
1 parent 1cd22bc commit e78cf17
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions examples/PSB2/annotations/spin_words.ae
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
type List;

def String_len : (i:String) -> Int = native "lambda i: len(i)";
def String_list_to_String : (l:List) -> String = native "lambda l: ' '.join(l)";
def map_String_String_List: (function:(a: String) -> String) -> (l: List) -> List = native "lambda f: lambda xs: map(f, xs)";
def String_split : (i:String) -> (j:String) -> List = native "lambda i: lambda j: i.split(j)" ;
def String_reverse : (i:String) -> String = native "lambda i: i[::-1]";

def spin_words (phrase: String) : String {
words: List = String_split(phrase)(" ");
reversed_words: List = map_String_String_List ((\x -> if (String_len(x) >= 5) then String_reverse(x) else x):(x:String)->String) (words);

String_list_to_String(reversed_words)
}

def main (args:Int) : Unit {
print (spin_words("this is another test"))
}

0 comments on commit e78cf17

Please sign in to comment.