Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote promise macro #54

Closed
jcubic opened this issue Jun 3, 2020 · 4 comments
Closed

Quote promise macro #54

jcubic opened this issue Jun 3, 2020 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@jcubic
Copy link
Collaborator

jcubic commented Jun 3, 2020

Here is problematic code:

(let ((x (Promise.reject (new Error "zonk"))) 
      (y (Promise.resolve 10)))
   (+ y y))
zonk
(let* ((x (Promise.reject (new Error "zonk"))) 
       (y (Promise.resolve 10)))
   (+ y y))
zonk

second promise is ignored because first rejects, this will print error "zonk" in terminal (looks better on the web).

TODO:
Need to figure out how to make it work. Possible solutions are:

  • operator that stop resolving of promises (it can work like quoting)
  • don't resolve promises when function is method of Promise probably will not work when it's wrapped.
@jcubic jcubic added bug Something isn't working enhancement New feature or request labels Jun 3, 2020
@jcubic jcubic added this to the 1.0 milestone Jun 3, 2020
@jcubic
Copy link
Collaborator Author

jcubic commented Jun 3, 2020

Possible solution - first one:

'>(Promise.reject (new Error "zonk"))

this will quote the promise. tranlsate into

(quote-promise (Promise.reject (new Error "zonk")))

maybe also `> quasi-quote-promise single based quasiquote that allow to use ,> to resolve the promise.

@jcubic jcubic removed the enhancement New feature or request label Jun 3, 2020
@jcubic
Copy link
Collaborator Author

jcubic commented Jun 3, 2020

Good news that reject in fact throw exception, so it's normal that it break from expression.

(try
 (let ((x (Promise.reject (new Error "zonk")))
       (y (Promise.resolve 10)))
   (+ y y))
     (catch (e)
        (display "YES")))
YES

@jcubic jcubic added enhancement New feature or request and removed bug Something isn't working labels Aug 8, 2020
@jcubic jcubic changed the title Reject of one expression reject everything without option to stop Quote promise macro Aug 8, 2020
@jcubic
Copy link
Collaborator Author

jcubic commented Aug 8, 2020

This is not a bug, so the issue is now to create '> quote-promise macro. that will stop auto resolving of promises:

Note that expression that wrap promise is also a promise.

jcubic added a commit that referenced this issue Dec 19, 2020
Add await function and quote-promise
Add new parser extension '> for quote promise
Refactor new function names to snake case
jcubic added a commit that referenced this issue Dec 19, 2020
@jcubic jcubic closed this as completed Dec 19, 2020
@jcubic
Copy link
Collaborator Author

jcubic commented Feb 15, 2021

Example of usage for reference:

lips> (--> '>(fetch "https://terminal.jcubic.pl")
           (then (lambda (res) (res.text)))
           (then (lambda (text)
                   (print (. (text.match #/<title>([^>]+)<\/title>/) 1)))))

lips> (await (--> '>(fetch "https://terminal.jcubic.pl")
                           (then (lambda (res) (res.text)))
                           (then (lambda (text)
                                   (. (text.match #/<title>([^>]+)<\/title>/) 1)))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant