Frequently Asked Questions

Stratego -- Strategies for Program Transformation

About this FAQ

Q: Is there a list of Frequently Asked Questions about Stratego?

A: Until now there wasn't. This page is the place to ask questions and look for answers. If you have a question, add it here.

Installation

Q: I get errors when compiling Stratego programs or when running compiled Stratego programs.
A: If you've carefully followed the installation instructions and you are still having problems, please file a bug report. Make sure to specify your configuration (OS, gcc version, Stratego version), include the error message and if posisble try to reduce to problem to a small piece of code.

Q: Does Stratego/XT support Microsoft Windows?
A: Yes, Stratego/XT works on Microsoft Windows + Cygwin. We provide binary distributions.

Q: Does Stratego/XT support Mac OS X?
A: Yes, Stratego/XT works on Mac OS X. We provide binary distributions.

Stratego interpreter

Q: How do I proceed to write Stratego code that's both interpretable and compilable? Is that a goal for the interpreter that this is possible ?

A: Yes, the compiler and the interpreter work on the same language. You can consider the list of commands in a script as the main strategy of a specification. There should be no difference in semantics between the compiler and the interpreter. Except for the fact that there is a definition before use regime in the script itself (not in modules imported in the script). That is, that is defined in the script can only be used (in a command) after it has been declared.

Debugging

Q: How do I get more debugging info ? The tools are awfully quiet unless I chock my code full of debug invocations. Can I somehow set up an 'exception handler' that shows the traversed stack and line number (or something similar) when a rewriting fails miserably?

A: See debugging techniques

Stratego language

Q: What is the difference between a strategy and a rule?

A: See rules versus strategies

Q: In what ways can variables be bound?

A: A variable is only bound during matching. That is, while applying a pattern match ?t to the subject term. All constructs that bind variables, ultimately use this pattern matching construct to bind variables.

Dynamic rules

Q: I get unexpected behaviour with two different dynamic rules with the same label.

A: If you are not using Stratego/XT 0.14 or later please upgrade. For more information see dynamic rule semantics.

Stratego standard libary

Q: collect removes duplicates, is there collect-with-duplicates?

A: Yes, there is. The collect strategy is an alias of collect-om. collect-om has a variant that takes a strategy argument that is used to combine intermediate results. If you pass conc instead of union, then duplicates will not be removed.

Q: Is it possible to redirect the stderr of process to a file in Stratego?

A: Yes, this works exactly the same a redirection in C. Example:

    module example
    imports posix-file char-io

    strategies

      main =
          <open> "error.txt" => fd
        ; <dup2> (fd, <STDERR_FILENO>)
        ; <debug> "bla bla bla 1"
        ; <fputs> ("bla bla bla 2", <stderr-stream>)
        ; <close> fd
See 'man dup2' for more information.

If you want to execute a new process, the following strategy is useful:

  /**
   * Execute program in a new process with list of string args, 
   * with the specified exec strategy.
   *
   * Optionally you can define file descriptors to use for stdin, stdout,
   * stderr.
   *
   * @param  opt-fdin   Option(FileDescr)
   * @param  opt-fdout  Option(FileDescr)
   * @param  opt-fderr  Option(FileDescr)
   *
   * @type  (String, List(String)) -> ()
   */
  call(|opt-fdin, opt-fdout, opt-fderr) =
      ?(prog, args)
      ; fork-and-wait(
          <option(<dup2> (<id>, <STDIN_FILENO> ))> opt-fdin
        ; <option(<dup2> (<id>, <STDOUT_FILENO>))> opt-fdout
        ; <option(<dup2> (<id>, <STDERR_FILENO>))> opt-fderr
        ; <execvp> (prog, args)
        ; <exit> 1
        )
      ; !()

This strategy is part of the Stratego Library.