deleted by creator
I’m here to stay.
deleted by creator
Ok I see, I stand corrected then. Its a misconception I had without actually going through all of this, so my bad (will edit my replies to mark them). At least in Python we can do this print(foo := (bar := 3))
but not on its own as foo := 3
.
But that mathematical pseudo code has nothing in common with the walrus operator (Edit: I’m so sick of my stupidness.):=
in Python and Go. They are just the same symbols, but with a totally different meaning and use case. Its an operator designed specifically for programming languages, because that is not applicable to mathematics at all. In mathematics you don’t have an assignment operator a = 69
that cannot be used as part of an expression. Therefore you don’t need a dedicated :=
that yields an expression that can be used as part of an expression and create a variable if its not already.
Turns out it was introduced in 3.8, released in 2019, so it was much too late to inspire Go
You are probably right about that. But don’t forget that the operator didn’t made it day one, there was lot of discussion before and probably testing it in the beta releases before. But given how old Golang at that point is, you are right about my take on inspiration. This operator wasn’t a new invention in Python.
It also has a substantially different meaning than in Go.
I don’t know if there’s an “official” rationale for the Go syntax, but := is a fairly common (but not ubiquitous) math notation meaning “define the thing on the left to be equal to the expression on the right”, i.e. to distinguish it from the other use of =, i.e. “the expression on the left must be equal to the expression on the right.”
Does it though? In both cases, Go and Python, the operator will assign a variable a value and also use it as an expression. That is useful in cases like for loops or other cases where you want immediately use the variable content as an expression. This cannot be done with the regular assignment operator (Edit: Read the reply, I learned something myself. That’s why its important that you don’t blindly teach people like I did.)a = 69
, which itself is not an expression. So in practical terms, its the same in usability for Go and Python. So its doing the same for both languages and has the same differences to the assignment operator.
deleted by creator
The :=
operator is called walrus operator and is inspired by Python I think. It’s declaring a variable and assigning it in one go. map[string] int
is defining a map (associative array or also known as dictionary in Python), with string as key type and int as value type. And the following {}
is the body of the associative array, meaning empty content.
I only played a bit with Go and did basic tutorials. I might go back to it at some point, but Zig is much more appealing to me. Go is too simple in the language to me, but on the other side, this is exactly whats appealing.
I’m not sure if this is relevant, but the first thought reading this is, aren’t the IPs shared too? I mean everyone connecting to the Torrent / page would be able to read from everyone connecting to it. But again, I have no idea if this is applicable in such a case. It’s just what I think when reading Torrent, that’s the extent of my knowledge.
Was posted a few hours before and has many comments: https://beehaw.org/post/13943043
I copied the sub-headings from the document, serving as an overview:
The only issue I have is the name of the project. They should have gone with a more distinct name.
I see, it’s a universal solution. But the produced code is not optimal in this case. I believe the Amber code SHOULD analyze it and decide if a more direct and simple code generation for Bash is possible. That is what I would expect from a compilers work. Otherwise the generated code becomes write only, not read only.
But its the other way, not analyzing Bash code. The code is already known in Amber to be an expression, so converting it to Bash expression shouldn’t be like this I assume. This just looks unnecessary to me.
Especially as Bash can do that anyway with if [ "${__0_age}" -lt 18 ]
as an example, and could be straight forward. Also Bash supports wildcard comparison, Regex comparison and can change variables with variable substitution as well. So using these feature would help in writing better Bash. The less readable output is expected though, for any code to code trans-compiler, its just not optimal in this case.
deleted by creator
Basically another shell scripting language. But unlike most other languages like Csh or Fish, it can compile back to Bash. At the moment I am bit conflicted, but the thing it can compile back to Bash is what is very interesting. I’ll keep an eye on this. But it makes the produced Bash code a bit less readable than a handwritten one, if that is the end goal.
curl -s "https://raw.githubusercontent.com/Ph0enixKM/AmberNative/master/setup/install.sh" | $(echo /bin/bash)
I wish this nonsense of piping a shell script from the internet directly into Bash would stop. It’s a bad idea, because of security concerns. This install.sh script eval and will even run curl itself to download amber and install it from this url
url="https://github.com/Ph0enixKM/${__0_name}/releases/download/${__2_tag}/amber_${os}_${arch}"
… echo “Please make sure that root user can access /opt directory.”;
And all of this while requiring root access.
I am not a fan of this kind of distribution and installation. Why not provide a normal manual installation process and link to the projects releases page: https://github.com/Ph0enixKM/Amber/releases BTW its a Rust application. So one could build it with Cargo, for those who have it installed.
The other person got me the solution. __new__()
is no longer needed to be overwritten anymore.
I think in Python 3.11 and prior overriding new was needed in order to subclass it correctly, because it was buggy until 3.12. This was a workaround, if I remember correctly. I already tried without new and setting self__source, but couldn’t make it work. I was close!
With your suggestion it works now! I will need to test the app a bit now and if everything looks fine, will update the repository. Did exactly what you said and replaced this part:
# class File(PosixPath):
# def __new__(cls, *args: Any, **kwargs: Any) -> Any:
# return cls._load_parts(args).expanduser().resolve() # type: ignore
#
# def __init__(self, source: str | Path, *args: Any) -> None:
# super().__init__()
# self.__source = Path(source)
#
class File(PosixPath):
def __init__(self, source: str | Path, *args: Any) -> None:
self.__source = Path(source)
super().__init__(Path(source, *args).expanduser().resolve())
Thank you for the help and solution!
Edit: Forgot to answer your question. This could work without subclassing too off course, but doing it this way makes it more clean in my opinion. It’s the natural way to me to extend functionality and use the extended version for the purpose its designed to. It’s not strictly required and I would have done it otherwise too, if this was problematic and not working.
From https://github.com/python/cpython/blob/3.12/Lib/pathlib.py
class PosixPath(Path, PurePosixPath):
"""Path subclass for non-Windows systems.
On a POSIX system, instantiating a Path should return this object.
"""
__slots__ = ()
if os.name == 'nt':
def __new__(cls, *args, **kwargs):
raise NotImplementedError(
f"cannot instantiate {cls.__name__!r} on your system")
Which sub classes PurePosixPath, which itself is basically just PurePath with a Posix flavour to it. And Path itself is PurePath as well. Not sure if I should copy paste them here.
Edit: So I added these to my reply:
def __new__(cls, *args, **kwargs):
"""Construct a PurePath from one or several strings and or existing
PurePath objects. The strings and path objects are combined so as
to yield a canonicalized path, which is incorporated into the
new PurePath object.
"""
if cls is PurePath:
cls = PureWindowsPath if os.name == 'nt' else PurePosixPath
return object.__new__(cls)
def __init__(self, *args):
paths = []
for arg in args:
if isinstance(arg, PurePath):
if arg._flavour is ntpath and self._flavour is posixpath:
# GH-103631: Convert separators for backwards compatibility.
paths.extend(path.replace('\\', '/') for path in arg._raw_paths)
else:
paths.extend(arg._raw_paths)
else:
try:
path = os.fspath(arg)
except TypeError:
path = arg
if not isinstance(path, str):
raise TypeError(
"argument should be a str or an os.PathLike "
"object where __fspath__ returns a str, "
f"not {type(path).__name__!r}")
paths.append(path)
self._raw_paths = paths
def __init__(self, *args, **kwargs):
if kwargs:
msg = ("support for supplying keyword arguments to pathlib.PurePath "
"is deprecated and scheduled for removal in Python {remove}")
warnings._deprecated("pathlib.PurePath(**kwargs)", msg, remove=(3, 14))
super().__init__(*args)
def __new__(cls, *args, **kwargs):
if cls is Path:
cls = WindowsPath if os.name == 'nt' else PosixPath
return object.__new__(cls)
Or on Linux systems as well. Another reason why Open Source / Libre Software is not only important, but essential to keep the freedom of users intact. There is no tracking, no artificial limitation from Oracle and no cost involved as well.
The Java implementation from Oracle needs to die. Everyone should switch to openjdk or stop using Java.