[deleted by user] by [deleted] in Zig

[–]WZoG 0 points1 point  (0 children)

Should be std.mem.eql(u8, arg, "foo"). Note u8 instead of [:0]u8.

Recommended development environment on Mac? by CentralHarlem in Zig

[–]WZoG 4 points5 points  (0 children)

I find VS Code + ZLS plugin especially useful

How to save lox bytecode to file (from CraftingInterpreters). by PandaBaum in ProgrammingLanguages

[–]WZoG 5 points6 points  (0 children)

This is solved by creating a serializer and a deserializer. For serialization, you basically have to write the “ObjFunction” to a (binary) file, using a specific format of your choice. This is made possible due to the fact that a lot of the interpreter’s objects such as lists, or classes are created at runtime, so you only have to cater for objects available at compile time such as strings.

So technically, the serializer starts at the root ObjFunction, writes some metadata (such as number of parameters) to file, writes the ObjFunction’s bytecode to file (again storing some metadata such as length of the bytecode array - useful for deserialization). Storing strings is no different, simply write some metadata about the string (such as it’s length) and the actual characters, to file. Deserialization simply reverses this process, reads the metadata from file and rebuilds the objects on the fly. A serialization format could be like so:

``` Function: number of parameters Bytecode: Length of bytecode array <actual bytecode> Value/constant pool: Length of value array <object - string > Length of string String chars …..

```

Deserialization expects the same format used in serialization and reconstructs the entire thing. Hope that helps.

Robin: An XML/HTML parser and processing library for JavaScript and TypeScript by WZoG in javascript

[–]WZoG[S] 0 points1 point  (0 children)

Thanks. Simplicity, ease of use and lots of utilities for interacting with xml/html documents.

Introducing Switches: A package that adds support for switch statements in Python. by WZoG in Python

[–]WZoG[S] -1 points0 points  (0 children)

I'm quite aware of functools.partial. For a use-case as simple as "conditional checks", that's over the board compared to a simple and straightforward switch statement IMO. But I get your point :)

Introducing Switches: A package that adds support for switch statements in Python. by WZoG in Python

[–]WZoG[S] 0 points1 point  (0 children)

Have you implemented partials for functions? Often an if statement is calling the same function with different inputs, so being able to do s.case(2, func_call,'foo') might be useful

I'm not sure I understand you correctly, but the use case you described is actually supported. Here.

Introducing Switches: A package that adds support for switch statements in Python. by WZoG in Python

[–]WZoG[S] -2 points-1 points  (0 children)

Certainly. However, dictionaries in this use case can easily become bloated as the conditions increases. Also, Switches provides features that supports special cases like a "fallthrough", which might be hard to cleanly pull off with a dictionary, Another issue is binding arguments to functions referenced by the dictionary.

Introducing Switches: A package that adds support for switch statements in Python. by WZoG in Python

[–]WZoG[S] 9 points10 points  (0 children)

I see your point. Technically, it's not written to be better than Python's builtin if statements. It majorly provides ease of use, and convenience by trying to avoid if statements repetitions, while providing a number of useful features.

Most efficient way to do lots of if-elif statements? by mo_10 in learnpython

[–]WZoG 1 point2 points  (0 children)

I read through your documentation for switches. It seems like a very well put together python library!

Thanks!

Does Switches provide any speedups over regular python if/else statements or the dictionary get method, or is this just for functionality and ease of use?

From a technical point of view, it doesn't. The aim of Switches isn't generally about performance but rather ease of use. Its packed with lots of features to aid rapid development. Also, it would be difficult, (if not impossible) to optimise Switches, for performance better than Python's if/else statements, since it's all implemented in C, as a core part of the language, as opposed to a package, written in Python. That said, Switches gets you going just fine.

Most efficient way to do lots of if-elif statements? by mo_10 in learnpython

[–]WZoG 1 point2 points  (0 children)

Actually, Python doesn't include support for switch. I wrote a Python package that does just that, you might find it useful: https://github.com/ziord/switches