Comments (5)
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.
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.
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.
Thanks understood. Makes sense. I'l continue the second few steps into my BQN adventure!
from bqn.
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)
- Explain the use of `under ⌾` primitive in tutorial/variable.md HOT 1
- Keyboard special character map HOT 6
- VM docs for `+` don't mention monadic case
- Roadmap HOT 1
- Installation confusion HOT 3
- Allow Emojii variable names HOT 6
- Confusing Take error in REPL HOT 1
- :bug: Grade Up/Down Broken HOT 4
- Hovering on Scan in the online REPL does not show input help HOT 4
- Small typo in Array Language Complilation
- Macron not explained in expressions tutorial HOT 2
- The example of `Switch` produces an error HOT 1
- Request for flashy examples in docs HOT 2
- Idea: BRFI? HOT 3
- 3 | ¯4 results in 2 in BQNPAD and the online REPL HOT 2
- Tutorial: 1-Modifier example HOT 1
- Graph unfriendly to color-blindness HOT 1
- Typo in bqnpad ceiling operator HOT 1
- Unfinished documentation HOT 1
- Mention VS Code extension in Editor Support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bqn.