From d0cbf9072ece79a61440e1cf4771a6632cfbd2f4 Mon Sep 17 00:00:00 2001 From: Jakub Jankiewicz Date: Mon, 25 Mar 2024 18:57:09 +0100 Subject: [PATCH] update LIPS intro tutorial --- docs/docs/lips/intro.md | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/docs/docs/lips/intro.md b/docs/docs/lips/intro.md index bde47a60..9c980673 100644 --- a/docs/docs/lips/intro.md +++ b/docs/docs/lips/intro.md @@ -322,8 +322,8 @@ The same as with JavaScript if you don't pass an argument it will be undefined. ``` ### Helper macros and functions -The most usefull macro in LIPS (for interacting with JavaScript) is `-->` it -acts like a chain of method calls in JavaScript +The most usefull macro in LIPS (for interacting with JavaScript) is `-->` it acts like a chain of +method calls in JavaScript ```scheme (--> "this is string" (split " ") (reverse) (join " ")) @@ -337,7 +337,28 @@ is the same as JavaScript: "this is string".split(' ').reverse().join(' '); ``` -#### Lagacy macros and functions +With --> you can also gab property of a function: + +```scheme +(--> #/x/ (test.call #/foo/ "foo")) +;; ==> #t +(let ((test-bar (--> #/x/ (test.bind #/bar/i)))) + (test-bar "BAR")) +;; ==> #t +``` + +You can also return a function: + +```scheme +(define test (--> #/x/ test)) +(test.call #/foo/ "foo") +;; ==> #t +``` + +Read more about [function::bind](https://tinyurl.com/ykvb836s) and +[function::call](https://tinyurl.com/yc6j7fdh) on [MDN](https://developer.mozilla.org/en-US/). + +#### Legacy macros and functions There are two legacy macros that are still part of LIPS, but you don't need them most of the time. @@ -348,7 +369,10 @@ them most of the time. (. document 'querySelector) ``` -This returned function querySelector from document object in browser. +This returned function querySelector from document object in browser. Note that dot a function can only appear +as first element of the list (it's handled in special way by the parser). In any other place dot is a pair separator, +see documentation abount [Pairs in Scheme](/docs/scheme-intro/data-types#pairs). + * `..` - this is a macro is that simplify usage of `.` procedure: ```scheme