duckscript
duckscript copied to clipboard
eval to support math comparison
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
you have calc + less/greater/eq commands. isn't it working for your use case?
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
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.
calc (current_time) - 48*60*60*1000will 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:
- Find
$(inner) - Replace it with
${var_name} - 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.
can you explain a bit more? maybe put some small example?
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.