朱莉娅(Julia)的OOP替代品

发布于 2025-01-21 22:13:50 字数 171 浏览 4 评论 0原文

我正在尝试学习一些朱莉娅,所以我正在写一些语言的小项目。

我想在朱莉娅(Julia)中写一个简单的感知者,但它不是面向对象的,所以我不能创建类perceptron,例如在python中,

可以在python中编写代码的替代方法是什么?我看到有结构,但这看起来像C结构,所以我想知道是否有更强大的方法。

I'm trying to learn a bit of Julia, so i'm writing some small projects in the language.

I'd like to write, for example, a simple Perceptron in Julia, but it is not object oriented, so i can't create a class Perceptron, like in python

What is a possible alternative to write a code like in Python? I saw that there are structures, but this looks like C structure, so I was wondering if there is a more powerful way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不语却知心 2025-01-28 22:13:50

您正在寻找的“更强大的方式”是类型层次结构系统: https:// /docs.julialang.org/en/v1/manual/types/

在朱莉娅(Julia Supertype必须是抽象类型,也有参数化类型的子类型,但是它们不是用<:>)

子类型保留父母的方法专业化,除非您更改其定义。

朱莉娅(Julia)亚型对抽象类型的影响之一是孩子们不继承父母领域(因为他们没有一个)。

The "more powerful way" you're seeking is the type hierarchy system: https://docs.julialang.org/en/v1/manual/types/

In julia, despite not being OOP, you can still subtypes other types with <: when making its definition (but the supertype must be an abstract type, there are subtypes of parametrized type too, but they aren't made with <:)

The subtypes keep the method specialisation of their parents, unless you change their definition.

One of the effect of Julia subtyping on abstract types is that childs don't inherit of parents fields (as they just don't have one).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文