具有NULL参数的Julia函数 [英] Julia function with NULL argument

查看:48
本文介绍了具有NULL参数的Julia函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R中,您可以在类似的函数中使用NULL参数 myfun =函数(a = NULL,b,c) 你能在茱莉亚做到这一点吗?我问是因为我想将变量a作为条件:如果a = NULL则执行此操作,否则执行该操作.我当然可以编写不同的函数,但是它们通常会彼此重复.我也可以分配任意数字,但使用NULL似乎更清楚.谢谢!.

In R you can use NULL arguments in functions like myfun = function (a=NULL, b, c) can you do this in Julia? I'm asking because I'd like variable a as a condition : if a = NULL do this, else do that. I can just write different functions of course but they would mostly repeat each other. I can also just assign arbitrary numbers but it seems using NULL is more clear. Thanks!.

推荐答案

使用一种新语言的人们最常见的问题之一是如何完全像他们所使用的语言一样进行编码.但是测试NULL可能不是在Julia中实现此功能的最佳方法.通常,您将为函数定义两种方法:

One of the most common questions from people coming to a new language is how to code exactly like in the language they come from. But testing for NULL is not likely to be the best way to implement this in Julia. Mostly you'll define two methods for your function:

function myfun(a, b, c)
    ...
end

function myfun(b, c)
    ...
end

具有不同的行为.

这篇关于具有NULL参数的Julia函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆