Comments (3)
Generally references (i.e. disguised pointers but with less free semantics) are a necessity for a general purpose language. I think pointers (i.e. the free semantics as pointer arithmetic etc.) should definitely be disallowed by default like Rust, V, and other modern langs do. And only allowed in some sort of unsafe { }
block or other visually explicit denotation.
A few open questions:
- Should we introduce new syntax for dereference and address-of operations? We could replicate C-style
&val
and*ptr
syntax with a few new tokens. One less-invasive alternative would be Zig-style dot syntax:val.&
andptr.*
would be easily expressed in the current Basil semantics.
By default (say outside of unsafe { }
blocks) a reference (pointer) shall be fully indistinguishable from a non-reference (non-pointer) value. Many newer as well as older/traditional languages have proven that it's really unnecessary to make it explicit because safe built-in statements/operations behave on the surface the same as with non-ref values. And it seems making it explicit (that we want to deal with a ref) just on one place (e.g. during function argument definition) is more than enough.
- Perhaps we could add some easier pointer arithmetic instructions than converting to and from
Int
? Maybe it could be type-based:ptr + Int
could add the size of anInt
to the address contained inptr
.
Yep, why not. But only in the unsafe { }
block. Otherwise compile-time error
from basil.
I'm kind of morally opposed to unsafe
as a language feature - if we add a perfectly functional feature that is often the best solution to a problem, why actively discourage its use? I don't think it fits Basil's theme of flexibility to strike down useful features as "undesirable"...and deal with that in no way other than to make that feature more annoying. It's a little more justifiable in Rust due to their static analysis, but Basil is garbage collected! So we don't need to limit ourselves in order to get memory-safe allocations.
If it wasn't clear though, the predominant approach towards reference semantics and memory management will be through safe, garbage-collected reference types - I've created a new issue for those, and the intent is that they'll be the recommended kind of pointer type for most workloads.
from basil.
Ah, ok. This reminds me of Nim's references.
Now it's clear that it should be easy to judge about the source code whether we're dealing with "dangerous pointers" or "safe pointers". That could be enough for me as a linter or some compiler option (akin to -Werror
-Wall
-Wextra
or perhaps -Wpointer
) could be made to fail compilation of sources with raw pointers
from basil.
Related Issues (20)
- Attributes/annotations HOT 1
- Escaped double quote lexes twice when next to start/end of string HOT 1
- Unable to lex escaped backslash in string literal HOT 1
- String formatting HOT 1
- Thoughts about a flexible yet compile-time turing complete language HOT 2
- Better pretty printing
- Continuation Passing Style (CPS) and compile-time evaluation (and parallelism/concurrency) HOT 4
- Control flow abstraction to avoid built-in exceptions, defer, multi-return, error handling, nil, etc. HOT 3
- Syntax sugar and other tricks for inspiration HOT 2
- XL lang with some similarities to Basil HOT 1
- Vaporization instead of reference counting to jump to the close-to-metal language battleground HOT 3
- Interpreted concatenative language ;) HOT 1
- Dreaming about end-user/programmer use-cases HOT 2
- Add floating-point primitives. HOT 4
- Add sub-64-bit integer types as primitives. HOT 1
- Tracing garbage collection. HOT 6
- Add garbage-collected references and reference types. HOT 7
- Forms versus macros HOT 1
- Killer app/lib/built-in-feature to make Basil stand out
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 basil.