Comments (6)
What @AlexDaniel said: we should start with the problem. I speculate the problem is:
- It's tiresome to write
my Buf $x .= new; $x.write-int32(42);
to get aBuf
containing the encoding of that integer value - There's no ideal way to get a
Blob
rather than aBuf
if wanting to have it as an immutable value
Those are probably fair problems, thought the solution proposed here doesn't seem ideal to me, since:
- Things like
Str
are alsoCool
, and having that be numified in response to.Buf
or.Blob
feels a bit odd. Folks would quite possibly expect it to do something like.encode
does. - There is no "correct size" for the integer 1. Depending on the needs of the binary format being produced, it could be represented in 1 byte, 2 bytes, 4 bytes, or 8 bytes.
I'd be more in favor of factory methods on Blob
/Buf
, so you could do Blob.from-int32(-1)
and it'd produce a 4-byte Blob
holding the representation of -1
; endianness can optionally be provided as it is in write-int32
.
from problem-solving.
While you're at it, how about taking an array (Iterable) as input as well?
from problem-solving.
OK, but which problem is this going to resolve?
Edit: Maybe it should be stressed in the README that the ticket should clearly explain what the problem is, before proposing a solution. We had a similar issue before: https://colabti.org/irclogger/irclogger_log/perl6?date=2019-04-05#l523
from problem-solving.
That'd work for me too :-)
from problem-solving.
@CurtTilmes Perhaps, but we have to be a bit careful, in that arrays in numeric contexts typically numify. It'd not be unreasonable for somebody to write my $chunk-count = Blob.from-int32(@chunks)
and expect to have a Blob
with the number of elements in the array encoded. It's a natural generalization for anyone happily doing if @stuff == 1 { }
and similar.
Maybe a plural version of the methods: Blob.from-int32s(@values)
?
from problem-solving.
Sounds good. I like this because it makes a few things easier.
Native types, shaped arrays, Blob-ifying numbers, etc. are on their way to competing with NumPy and PDL, but I still don't understand how it all fits together.
I like Blob
s because they are easy to work with for NativeCall
, but it seems that instead of converting from Int
to Blob
, I should be using an int32
that really already has the right representation under the sheets, right?
I shouldn't need to convert an array of int32
into a Blob
, I should just be able to use an array of int32
directly? Like if a library wants a huge array of int32
as a pointer and a size, what's the efficient way to send it there? I use Blob
s and CArray
s a lot, but it seems like I am doing extra work.
from problem-solving.
Related Issues (20)
- API for RakuDoc v2 HOT 2
- Inbound P6/Raku URLs are currently broken HOT 2
- http://doc.perl6.org/ --> https://docs.raku.org? (Thousands of inbound P6/Raku URLs are currently broken) HOT 7
- dd does not show coercion type on scalars HOT 5
- TAP refers to Perl 6 HOT 2
- LEAVE phaser with return HOT 46
- Metamodel concurrency problems HOT 17
- Named arguments don't respect canonical `key => value` convention (specific example of `mm-dd-yyyy` routine) HOT 15
- Add `.bufs`/`.blobs` methods to `IO::Path` / `IO::Handle` HOT 6
- `when` doesn't support smartmatching against a pointy block HOT 8
- Code highlighting / inspection / IDE tooling HOT 6
- Using multiple named arguments gives different result than just supplying value alone; specific example of `splice`. HOT 22
- Will we ever need more than 64K unique strings at compile time? HOT 4
- Add "short-index" version of often occurring ops HOT 1
- Behavior of type-constrained parameters is surprising given other behavior HOT 65
- Add `nomark` for striping accents, `samemark` is counterintuitive and slow for that purpose. HOT 3
- Root(s) - missing prefix operators HOT 1
- Enabling `no strict` for `raku` one-liners (and perhaps REPL) HOT 8
- Should `.flatmap` be really DEPRECATED or not? HOT 5
- Feature Request - method ```.hammer``` HOT 11
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 problem-solving.