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

Adding some conditionals in the language #924

Open
trefis opened this issue Jun 28, 2018 · 3 comments
Open

Adding some conditionals in the language #924

trefis opened this issue Jun 28, 2018 · 3 comments

Comments

@trefis
Copy link
Collaborator

trefis commented Jun 28, 2018

This is similar to #819 but with a somewhat broader scope.
The idea would be to support (if <cond> <then> [else]) at the toplevel of a jbuild.

This would allow encoding the example of #819, which was:

(alias
 ((name runtest)
  (deps (foo.exe))
  (action (run ${<}))
  (enabled_if (and (<> ${os} win32) (>= ${ocaml_version} 4.0.5)))))

as

(if (and (<> ${os} win32) (>= ${ocaml_version} 4.0.5))
    (alias
     ((name runtest)
      (deps (foo.exe))
      (action (run ${<})))))

(of course I have nothing with the sugar proposed in #819).

But would also allow doing things like:

(if (= ${ocaml_version} "4.07._")
    (copy_files# 407/*.ml{,i}))
(if (= ${ocaml_version} "4.06._")
    (copy_files# 406/*.ml{,i}))
...

which are needed for merlin and currently require us to use ocaml jbuilds.


I'm only proposing to support this at the toplevel, but this could be pushed down to arbitrary places (after all, (select ...) already does similar things).

@avsm
Copy link
Member

avsm commented Jun 29, 2018

Related to #838

@rgrinberg
Copy link
Member

#819 I've implemented the boolean sub language that is required for this feature.

Btw, I would prefer if we supported conditionals via pattern matching or a cond form.

I'd much rather write something like this:

(case %{os}
 ("win32" (copy_files ...))
 ("linux" (copy_files ...))
 (_ (copy_files ...)))

or

(cond
 (= %{os} "win32" (copy_files ...))
 (= %{os} "linux" (copy_files ...))
 (else (copy_files ...))

than the equivalent with if/else.

@trefis
Copy link
Collaborator Author

trefis commented Jul 22, 2018

That absolutely fine by me.

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

Successfully merging a pull request may close this issue.

3 participants