GithubHelp home page GithubHelp logo

Comments (5)

mlochbaum avatar mlochbaum commented on May 26, 2024 1

You're right that most APLs use ? for random number generation. I removed it in BQN and instead have defined system values to deal with random numbers, which are currently supported in CBQN. For example the common APL pattern ?4⍴6 would be written 4 •rand.Range 6.

The biggest reason not to make ? a primitive is that pseudorandom generation is stateful, and primitives in BQN are always stateless. Because BQN has the function •MakeRand to create a generator, it gives you much better control over the state, while APL's ⎕RL function doesn't scale well. With •MakeRand different parts of a program can have their own non-interfering generators. Depending on what it does, a tool might always use its own generator (possibly recording the seed), require the user to supply one, or use its own by default but allow the caller to override it. The fact that it's a namespace also allows us to easily add all sorts of distributions and special functions without having to make new primitives.

For areas where random generation is a central part of programming, •ReBQN (draft spec) would allow you to extend BQN with appropriate primitives. Something like the following. But right now only CBQN has •MakeRand and only the online REPL supports primitives⇐, so you can't run this code anywhere yet.

rand ← •MakeRand 1  # Initialize
bqn_rand ← •ReBQN {primitives⇐•primitives∾⟨⟨'?',rand.Range⚇0⊘rand.Deal⟩⟩}
BQN_rand "3?5"

from bqn.

mlochbaum avatar mlochbaum commented on May 26, 2024

If you get stuck on another primitive, the BQN-Dyalog dictionary has most of them. For ? it does point you to •MakeRand, although •rand would be more accurate now that it exists (added to CBQN three days ago).

from bqn.

mlochbaum avatar mlochbaum commented on May 26, 2024

Added •rand to the online REPL, so defining ? now works. •MakeRand would be harder because it can't use Math.random(), as that can't be initialized.

from bqn.

vegabook avatar vegabook commented on May 26, 2024

Thanks understood. Makes sense. I'l continue the second few steps into my BQN adventure!

from bqn.

vegabook avatar vegabook commented on May 26, 2024

Yeah giving this some more thought it does seem correct that any "primitive" that relies on a seed is no longer a primitive. Therefore this choice actually makes BQN purer in a mathematical sense.

from bqn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.