#What the hell I am doing wrong here?

1 messages · Page 1 of 1 (latest)

verbal birch
#

The code

`pub fn stripComments(self: *Lexer) !void {
var filtered = std.ArrayList(u8).init(self.allocator);
defer filtered.deinit();

    for (self.program) |byte| {
        switch (byte) {
            '+' | '-' | '<' | '>' | '[' | ']' | ',' | '.' => {
                try filtered.append(byte);
                std.debug.print("byte: {c}\n", .{byte});
            },
            else => {
                std.debug.print("bad byte: {c}\n", .{byte});
            },
        }
    }

    const program = try filtered.toOwnedSlice(); // Reemplaza el slice original con el nuevo.
    std.debug.print("program {s}\n", .{program});
    self.program = program;
}

`

self.program is []u8 with value "++++++++++[>+++++++>++++++++++>+++++++++++>+++>+<<<<<-]>++.>>+.---.<---.>>++.<+.++++++++.-------.<+++.>+.>+.>."
The output

bad byte: +
bad byte: +
bad byte: +
bad byte: +
bad byte: +
bad byte: +
bad byte: +
bad byte: +
bad byte: +
bad byte: +
bad byte: [
...
...
program

this says that in the switch all the bytes are bad bytes, which is the opposite, is this a bug in the compiler or I'm just skipping a mistake I made

tepid cedar
#

use , instead of | :P

#

you are bitwise orring the chars

verbal birch
verbal birch
tepid cedar
#

the future

vivid vine
#

ai loves sprinkling bits of rust into zig code

tepid cedar
#

last time it generated me a lambda / closure, it looked good but sadly not allowed

verbal birch
#

Yo can kinda use closures but in a Ziggy way

tepid cedar
#

yeah the anonymous struct trick

#

I prefer dependency injection anyways considering how simple it is to do in zig

#

though still requires passing function

verbal birch
#

I'm thinking of implementing a functional programming library for Zig.

#

To have beauties like map, take, skip, for, filter, etc

tepid cedar
#

I would find those useful at times

#

I'd like to see them in std actually, but not sure if andrew likes that :P

verbal birch
#

Implement it as interfaces so that all work is done in a single run, not multiple iterations (I'm looking at you, javascript)

tepid cedar
#

not imperiative nor functional purist

verbal birch
tepid cedar
#

well, sort is basically functional function though

#

I guess lack of real closures make it no go, or less ergonomic

verbal birch
#

But sort is made in-place, isn't it?

tepid cedar
#

yeah it's in-place

#

doesn't copy the data

#

the interface is functional though what I'm saying

#

you give input and predicate

#

where predicate == F

verbal birch
#

Yeah... that's not very functional programming on its part.

verbal birch
#

I got you

#

the u32_asc thing when you do asc(u32)

tepid cedar
#

yep it returns struct with the function

verbal birch
#

But thats only higher order functions

verbal birch
#

currying is like the only basic stuff that can be implemented that easy

tepid cedar
#

anyhow, map, filter, reduce, and such would make transforming data nice

verbal birch
#

0.12 is 87% complete, so I think I'll stick to that version for my lib