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

eval to support math comparison #31

Open
sagiegurari opened this issue Jan 4, 2020 · 7 comments
Open

eval to support math comparison #31

sagiegurari opened this issue Jan 4, 2020 · 7 comments
Assignees

Comments

@sagiegurari
Copy link
Owner

No description provided.

@sagiegurari sagiegurari self-assigned this Jan 5, 2020
@ModProg
Copy link

ModProg commented Feb 25, 2022

not sure what this would involve, but one feature that could fit in here is fish like command evaluation for inputs to other commands

so e.g. this could be supported:

if less_than (get_last_modified_time package.lock) (current_time)
    echo hi
end

@sagiegurari
Copy link
Owner Author

you have calc + less/greater/eq commands.
isn't it working for your use case?

@ModProg
Copy link

ModProg commented Feb 25, 2022

It might just be that I'm not very experienced with duckscript, but this got rather lengthy.

package_lock_modified = get_last_modified_time yarn.lock 
current_time = current_time
current_time = calc ${current_time} - 48*60*60*1000
less_than_two_days_old = less_than ${package_lock_modified} ${current_time} 
package_json_newer = is_path_newer package.json yarn.lock
if ${less_than_two_days_old} or ${package_json_newer}
    exec --fail-on-error yarn
    exec touch yarn.lock
else
    echo "Packages up to date"
end

I would have prefered to be able to do something like this:

if (less_than 
        (get_last_modified_time yarn.lock)
        (calc (current_time) - 48*60*60*1000)) 
    or (is_path_newer package.json yarn.lock)
    exec --fail-on-error yarn
    exec touch yarn.lock
else
    echo "Packages up to date"
end

@sagiegurari
Copy link
Owner Author

ya the conditions are a bit basic in their capabilities and duckscript in general has 1 command per 1 line rule.
also per the format of output=command args this one: calc (current_time) - 486060*1000 will probably never be implemented.

@ModProg
Copy link

ModProg commented Feb 27, 2022

calc (current_time) - 48*60*60*1000 will probably never be implemented.

Makes sense. I just thought it might be a useful feature to basically have a shortcut to always needing to move everything in a variable.

Fish follows a similar approach, wanting to have a simple syntax that prefers e.g. commands over language features, that's why I proposed their syntax.

Thinking about it, maybe something more inline with the variable expansions $(...) would maybe make more sense and also lowers the risk of accidentally triggering it.

It should also not increase the implementation complexity too much, as the implementation could basically be:

  1. Find $(inner)
  2. Replace it with ${var_name}
  3. Introduce new variable in line above var_name = inner

Probably makes not a lot of sense to actually implement it like that, but I would find it quite useful.

@sagiegurari
Copy link
Owner Author

can you explain a bit more? maybe put some small example?

@ModProg
Copy link

ModProg commented Mar 1, 2022

can you explain a bit more? maybe put some small example?

Basically my example from above.

A bit simplified, this:

if less_than $(get_last_modified_time file) $(calc $(current_time) - 100)
    echo true
else
    echo false
end

Should internally expand to

__get_last_modified_time = get_last_modified_time file
__current_time = current_time
__calc = calc ${__current_time} - 100
if less_than ${__get_last_modified_time} ${__calc}
    echo true
else
    echo false
end

I used __ to mark internal variables. But they probably don't even need names.

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

No branches or pull requests

2 participants