Giter Club home page Giter Club logo

Comments (4)

edemaine avatar edemaine commented on June 23, 2024 1

Pipe conditions do seem like a reasonable possible approach. We might need one for truthy and one for nonnull. We've talked about ?|> before to act like "if nonnull, then pipe into rhs".

Given how much guard resembles unless, I'd be tempted to spell it like so:

unless x? := getX()
  throw new Error "Missing x coordinate"
unless y? := getY() then return
unless z? := getZ() then return
setPoint x, y, z

#756 points out that our current meaning of unless x := ... isn't very helpful; it just exposes a falsey value for x inside the block. The proposed alternative would be to expose the declaration outside the unless block instead — essentially opposite of if, which kind of makes sense?

Alternatively, we could pull the declaration outside:

x := getX() ?? throw new Error "Missing x coordinate"
y := getY() ?? return
z := getZ() ?? return
setPoint x, y, z

This works for throw, but not for return, because we don't yet have a way to expressionize return. When it's at the top level of a declaration like this, I imagine we could handle it though.

from civet.

bbrk24 avatar bbrk24 commented on June 23, 2024

Supersedes #756 I suppose

from civet.

STRd6 avatar STRd6 commented on June 23, 2024

A couple thoughts:

I'm reluctant to add any more reserved words like guard. Would unless x? := getX() else return be an acceptable spelling of this feature?

Maybe upgrading pipes to better handle piping to return/throw and allowing something similar to declaration conditions could help with this. #897 (comment)

x := getX() !> return
---
let ref = getX(); if(!ref) return ref; const x = ref;

Possible conditional pipe options: ?>, !>, ?|>, !|> maybe something else?

from civet.

bbrk24 avatar bbrk24 commented on June 23, 2024

unless-else reads like a double-negative, but otherwise I'd be fine with it.

from civet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.