Is there a way to run CBQN scripts, like #!/usr/bin/BQN on the first line and ⊑+`∘⌽⍟12↕2 on the second? I tried this but it didn't print anything when I ran it.
@jordancurve If you didn't get any error messages like "/usr/bin/BQN not found", I guess it ran fine but didn't print anything. You could try calling •Show on the result
@jordancurve I use #! /usr/bin/env bqn, which allows bqn to be located anywhere in the user's path like ~/bin/bqn or /usr/local/bin/bqn. And yes, there's no implicit output so you need •Show to look at results.
@pmikkelsen Have a look at :Require, however, your namespace really shouldn't "use" another. Only functions in the namespace should refer to other namespaces, and then loading order doesn't matter.
@Adám Thanks! Its part of doing advent of code, so I created a namespace for each day, and one for handling input. The code is very simple, so you can look at input.apln and day1.apln for example git.sr.ht/~pmikkelsen/apl-aoc2020/tree
@pmikkelsen OK, so the easiest fix is simply wrapping the content of the namespace in e.g. ∇run … ∇ and then, after importing the code, you run day1.run
fn uses the global variable data. Consider supplying it as an argument. E.g. I'd make the current ⍵ into ⍺ and use ⍵ for the data. This means that the final calls to fn would be 2 fn data and 3 fn data
@pmikkelsen Notice that I didn't have an underbar under ⍳ – cf. ⍸
result1← causes a new variable to be created in the namespace. A more functional approach would be to return the results. Now that you wrap in ∇run … ∇ you can make run return those two results, simply by amending to ∇(result1 result2)←run
@pmikkelsen Finally, you might want to adopt a naming convention to distinguish between functions like fn and variables like sum. For inspiration, have a look at abrudz.github.io/style/#nc