在Objective-C中,当我想调用子例程时,我向对象发送消息,如:
[self mySubroutine:myParameter];
有一个(可忽略的?)性能损失,所以我可以使用C风格的函数调用:
mySubroutine(myParameter);
后者的实现将存在于类的@implementation上下文之外.
这是不是吗?这很常见吗?这是最好的做法吗?
这些中最好的还是最差的方法之一?
利用范围:
my $cache = CHI->new( driver => 'File', expires_in => 3600 );
sub one {
if ( my $data = $cache->get( 'key_one' ) ) {
# ...
}
sub two {
if ( my $data = $cache->get( 'key_two' ) ) {
# ...
}
Run Code Online (Sandbox Code Playgroud)
传递对象作为参数:
my $cache = CHI->new( driver => 'File', expires_in => 3600 );
sub one {
my ( $cache ) = @_;
if ( my $data = $cache->get( 'key_one' ) ) {
# ...
}
sub …Run Code Online (Sandbox Code Playgroud) AutoHotkey命令Hotkey允许在运行时创建动态热键,但其语法和文档似乎将其限制为内置或现有标签/子例程,这使得它没那么有用:
热键,KeyName [,标签,选项]
有没有办法让它像普通的硬编码热键一样工作?例如:
#z::MsgBox foobar ; Typical, hard-coded hotkey pops up a message-box
Hotkey, z, MsgBox foobar ; Nope; complains about missing label “MsgBox foobar”
Run Code Online (Sandbox Code Playgroud)
看起来它可能是由于手册中的以下行,但不清楚它是如何工作的:
标签 - 可以使用普通标签和热键/热字符串标签.
运行perl 5.12.4在return语句中或之前分配散列时,函数的结果之间会出现差异.最简单的例子是:
perl -e 'sub s1 {
my @a=qw/b 1 c 2 a 3 a 4/;
my %h=@a;
return %h
}
print "@{[ s1()]}\n"'
c 2 a 4 b 1
perl -e 'sub s1 {
my @a=qw/b 1 c 2 a 3 a 4/;
my %h=@a;
return %h=@a
}
print "@{[ s1()]}\n"'
c 2 c 2 a c
Run Code Online (Sandbox Code Playgroud)
为什么(重新)在返回语句(第二个示例)中分配哈希会破坏返回的哈希?
我是一个相当特殊的applecripter,并且已经写了很长时间的脚本.我目前正在创建的应用程序涉及使用"数据库事件"应用程序.我试图通过使用子程序设置字段的值.显然,我"不能继续set_duration",我不知道会出现什么问题.目前的源代码如下.
property first_run : true
on run
if first_run then
display dialog "THIS APPLICATION IS DESIGNED TO CLEAN UP THE FOLDER CONTAINING IT." & return & return & "After a certain number of days that you set, every item in that folder that has not been used for that duration will automatically be moved to a folder named \"Unused Items\"." with icon 1 buttons {"Cancel", "OK"} default button 2
set first_run to false
end if
tell application "Database Events"
set …Run Code Online (Sandbox Code Playgroud) 我是Fortran的新手.我正在研究一个研究项目,我正在使用一个开源项目,该项目有多个文件分布在多个文件夹中.我发现每个程序的依赖性,但无法弄清楚如何编译它们.
我的源代码分布在三个文件夹中.a)模块b)接口c)子程序
我想在子程序文件夹中运行一个名为'Main.f90'的程序,该程序依赖于来自模块和接口文件夹的源代码.
我正在使用eclipse进行文件夹结构和makefile进行编译.
对此有任何帮助表示赞赏.
更新: 我按照@MBR和@Stefan发布的答案,由于某种原因VPATH无法在源代码中找到程序,所以我明确地给了我的Makefile中的源文件夹路径.下面是我的make文件脚本.
.PHONY: Mopac_exe clean
# Change this line if you are using a different Fortran compiler
FORTRAN_COMPILER = gfortran
SRC = src
#make main program
Mopac_exe: subroutines mopac.o
$(FORTRAN_COMPILER) mopac.o *.o -O2 -g -o bin/Mopac_exe -I Modules/
#compile all the subroutines
subroutines: interfaces
$(FORTRAN_COMPILER) -c $(SRC)/subroutines/*.F90 -J Modules/Subroutines/ -I Modules/
#compiles all the interfaces
interfaces: modules
$(FORTRAN_COMPILER) -c $(SRC)/interfaces/*.f90 -J Modules/
# build all the modules and generate .mod file in Modules …Run Code Online (Sandbox Code Playgroud) 我有下一个程序:
use warnings;
use strict;
BEGIN {
print \&mysub;
}
sub mysub {};
print \&mysub;
Run Code Online (Sandbox Code Playgroud)
它的输出:
CODE(0x118e890)CODE(0x118e890)
Run Code Online (Sandbox Code Playgroud)
该BEGIN块在编译时处理.那时sub mysub编译器还没有看到定义.但是程序仍会打印正确的子程序地址,它在定义时会有.
为什么我这里没有错误?这是某种自动化吗?
我已经阅读了http://www.perl101.org/subroutines.html但我只是不了解可选参数.
我想在PDF :: API2中调用以下子.该文件称"-indent"是一种选择.我如何为缩进20传递参数?
这就是我现在所经过的:
$txt->section($str, $contentwidth,$heightmax);
Run Code Online (Sandbox Code Playgroud)
这是子
Run Code Online (Sandbox Code Playgroud)sub section { my ($self,$text,$width,$height,%opts)=@_; my $overflow = ''; foreach my $para (split(/\n/,$text)) { if(length($overflow) > 0) { $overflow .= "\n" . $para; next; } ($para,$height) = $self->paragraph($para,$width,$height,%opts); $overflow .= $para if (length($para) > 0); } if (wantarray) { return ($overflow,$height); } return $overflow; }
Imagine that you have a module X whose functionalities are available to the user through a Command Line Interface. Such module doesn't do much in and of itself but it allows for other people to create plugin-like modules they can hook-up to module X. Ideally, the plugins could be used through X's CLI.
Thus my question:
What do you need to do in order to hook-up whatever functionality
a plugin might provide to X's CLI?
This …
在大型遗留代码中,在 END SUBROUTINE 之前使用简单的 RETURN 语句(不带任何参数)是一个好的做法,还是我们应该删除它?
我正在使用的代码是一个大型遗留代码(用于科学计算),其中部分代码最初是使用 Fortran 77 编写的,而大多数新开发是使用 Fortran 95 及更高版本编写的。还有一些散布的 C 代码和 Python 脚本。
英特尔开发人员指南明确提到 End Subroutine 已经启动 Return: https: //software.intel.com/en-us/fortran-compiler-developer-guide-and-reference-end
另一方面,我记得在 2000 年代就有人教导我,在 END SUBROUTINE 之前指定显式的 RETURN 语句始终是一个好习惯。
典型的子程序结构如下(例如,Chapman's Fortran for Scientifics and Engineers,第 4 版):
SUBROUTINE subroutine_name ( argument_list )
...
(Declaration section)
...
(Execution section)
...
RETURN
END SUBROUTINE [subroutine_name]
Run Code Online (Sandbox Code Playgroud)
如果 Return 语句(不带任何参数)不是一个好的实践,那么为什么还要将其作为结构的一部分提及,尤其是在“执行部分”之外?CYCLE 或 EXIT 等从未作为标准子例程结构的一部分被提及。那么,为什么要退货呢?
subroutine ×10
perl ×4
fortran ×2
return ×2
applescript ×1
arguments ×1
autohotkey ×1
c ×1
dynamic ×1
function ×1
gfortran ×1
hash ×1
hotkeys ×1
module ×1
multifile ×1
object ×1
objective-c ×1
perl6 ×1
raku ×1