Coder Social home page Coder Social logo

Comments (2)

sagiegurari avatar sagiegurari commented on July 24, 2024

wow, nice bug.
my guess error is false and it should go to else as default behavior.

the exit on err is default false since it is similar behavior in sh scripts.
you do a cd to nowhere and do rm and it will delete the wrong thing. although the cd did exit with 1.
its also very helpful when you run duck without args and use it interactive mode. you dont want it to die in the middle due to spelling.

as for silent, you can change it because its possible to have custom behavior on error

from duckscript.

sagiegurari avatar sagiegurari commented on July 24, 2024

@rustonaut ok, i looked at the code and things came back to me.
so if does one of the following (from https://github.com/sagiegurari/duckscript/blob/master/docs/sdk.md#std__flowcontrol__If):

  • A command with optional arguments and invokes it
  • A single value which doesn't match any known command
  • A condition statement

the first arg you gave is not a known command, so it is considered as a value.
however, you gave 2 args, so it doesn't match bullet 2 or 3 (condition statement is values with and/or....).
so the if fails as its just invalid input.
since errors by default do not break, it continues to next line, prints yes.
it than goes to the 'else'. however the else is also a command on its own and it sees its not invoked as part of an if/else block (because if failed to execute), so again, it just continues on.

so far the 'if' handling seems right to be, but the 'else' is something i need to think about.
reason is, that you can also goto directly into the else block and it would be ok, and when you hit an 'end' command, it will also ignore it. it makes sense since you can move to whereever at any point in the script.
it definitely feels strange and hard to debug at first, but it is due to the face that there are no real blocks in duckscript.

as for errors being silent, i actually put an example in the examples directory to make it echo
https://github.com/sagiegurari/duckscript/blob/master/examples/on_error_2.ds
so you can try that. but you can do even more smarter things if you really want.

i'm closing it for now, because although its confusing at first, you need to remember that if doesn't know how to differentiate between a command with spelling mistake and an actual text.

from duckscript.

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.