From 9bbef0c9136107ffc55f126938fc7936710039bb Mon Sep 17 00:00:00 2001 From: Vanessa McHale Date: Thu, 7 Mar 2024 18:26:34 -0500 Subject: [PATCH] old examples --- doc/guide.md | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/doc/guide.md b/doc/guide.md index 90f2bb64..69d1a82e 100644 --- a/doc/guide.md +++ b/doc/guide.md @@ -9,12 +9,9 @@ expressions scan for relevant output and one can split on separators. There is additionally support for filters, maps and folds that are familiar to functional programmers. -On Mac, one can use `otool -l` to show load commands and then select lines -specifying the `name`, extracting the second field: + -``` -otool -l $(locate libpng.dylib) | ja '{`1 ~ /^name/}{`2}' -``` + ## Language @@ -28,14 +25,21 @@ In Jacinda, one writes a pattern and an expression defined on matching lines, vi This defines a stream of expressions. -One can specify the field separator with `-F`: +One can search a file for all occurrences of a string: + +``` +ja '{% /Bloom/}{`0}' -i ulysses.txt +``` + +``0` here functions like `$0` in awk: it means the whole line. So this would print all lines that match the pattern `Bloom`. + +We could imitate fd with, say: ``` -printenv | ja -F= '{% /^PATH/}{`2}' +ls -1 -R | ja '{% /\.hs$/}{`0}' ``` -``2` here is like `$2` in awk: it is the second field in a line. So the above -matches all lines that start with `PATH` and prints the second field. +This would print all Haskell source files in the current directory. There is another form, @@ -47,11 +51,11 @@ where the initial expression is of boolean type, possibly involving the line context. An example: ``` -{ix>1}{`0} +{#`0>110}{`0} ``` -`ix` is the line number, and ``0` is like `$0` in awk, i.e. the whole line. So -this prints everything after the first line. +This defines a stream of lines that are more than 110 bytes (`#` is 'tally', it +returns the length of a string). There is also a syntax that defines a stream on all lines, @@ -111,7 +115,7 @@ let val in sum {% /Bloom/}{1} end ``` - + In Jacinda, one can define functions with a [dfn](https://help.dyalog.com/latest/#Language/Defined%20Functions%20and%20Operators/DynamicFunctions/Dynamic%20Functions%20and%20Operators.htm) syntax in, like in APL. We do not need to bind `x`; the variables `x` and `y` are implicit. Since