X-Git-Url: http://git.annexia.org/?a=blobdiff_plain;f=stdlib%2Fprelude.gl;h=d8e523ab539581ba52f89d13faa4c7dafe9dfac7;hb=6049de701cea350b3f474e4c1ff16836baa8e2fb;hp=7dc3b7342238c6b0cfb1dde70ff594c285c7f3e6;hpb=22e06eac0cf27c97056bb9e2f4fe7e45f7f1a474;p=goals.git diff --git a/stdlib/prelude.gl b/stdlib/prelude.gl index 7dc3b73..d8e523a 100644 --- a/stdlib/prelude.gl +++ b/stdlib/prelude.gl @@ -59,6 +59,16 @@ pure function wrap (wrapper, xs) = @{ #---------------------------------------------------------------------- # Text functions. +# Filter a list by regexp. +pure function filter (pat, xs) returning strings = @{ + for f in %xs; do echo "$f"; done | grep -E -- %pat +} + +# Filter out a list by regexp. +pure function filter-out (pat, xs) returning strings = @{ + for f in %xs; do echo "$f"; done | grep -v -E -- %pat +} + # Head of a list. pure function head (xs) returning string = @{ for f in %xs; do @@ -98,12 +108,12 @@ pure function tail (xs) returning strings = @{ # Base name. pure function basename (name) returning string = @{ - basename %name + basename -- %name } # Directory name. pure function dirname (name) returning string = @{ - dirname %name + dirname -- %name } # File extension. @@ -114,12 +124,12 @@ pure function extension (name) returning string = @{ # Read a file. function read (filename) returning string = @{ - cat %filename + cat -- %filename } # Read a file as a list of lines. function readlines (filename) returning strings = @{ - cat %filename + cat -- %filename } # Real path.