Skip to content

Batch Script Implementation

frenchy64 edited this page Apr 29, 2011 · 9 revisions

Batch Implementation Challenges

Arithmetic

Problem

Any arithmetic operations need to be prefixed with /a.

SET /a (2+2)*2

=> 8

This means we must have prior knowledge that we are dealing with numbers with a set!.

(set! x (+ 1 1))

=>

SET /a x=(1+1)

The below case needs to be discerned from the above.

(set! x "string")

=>

set x=string

Currently the (+ 1 1) is converted to (1+1) but there is no way for the set! command to know when to slot in an /a.

Suggested Solutions

Use an intermediate parsing phase.

(set! x (+ 1 1))

=>

(set-arith! x (+ 1 1))

=>

SET /a x=(1+1)

Function calls

Problem

Functions in batch are named with a label prefixed by :.

To call a function the CALL command is used. Unfortunately, this command is overloaded to also call internal commands.

CALL :Function1
CALL echo after function call

:Function1
echo this is an example function
GOTO :End

:End

=>

this is an example function
after function call

In Stevedore it might look like this:

(script
  (defn asdf []
    (echo "this is an example function"))
  (asdf)
  (echo "after the function call"))

There is however some ambiguity as to what (asdf) could mean in batch (either call asdf or call :asdf). There is no such ambiguity in Bash as commands and functions have the same syntax.

Proposed Solutions

Change function declaration syntax

(script
  (defn :asdf []
    (echo "this is an example function"))
  (:asdf)
  (echo "after the function call"))

+ve

  • No ambiguity in batch
  • bash could just parse out the semicolon prefix

-ve

  • Illusion of declaring first class functions (in the bash sense) is lost.

Overall, an unsatisfactory solution.