(2.) (런타임에 인수 목록을 얻음)에 대한 경로를 찾지 못했지만, 가치가있는 부분에 대해 (처리기의 구성 요소가 0), 실행 시간에 핸들러의 장점을 배울 수 있습니다.
-- RUN-TIME TEST:
-- HOW MANY ARGUMENTS DOES A HANDLER EXPECT ? --------------------------------
-- arityAndMaybeValue :: Handler -> {arity: Int, nothing: Bool, just: Any}
on arityAndMaybeValue(h)
try
set v to mReturn(h)'s |λ|()
{arity:0, nothing:false, just:v}
on error errMsg
{arity:length of splitOn(",", errMsg), nothing:true}
end try
end arityAndMaybeValue
-- TEST ----------------------------------------------------------------------
on run
-- Arities for zipWith and helloWorld handlers
{arityAndMaybeValue(zipWith), arityAndMaybeValue(helloWorld)}
-- If the arity was 0, then a return value is is given
-- in the 'just' key of the record returned.
-- otherwise, the 'nothing' key contains the value `true`
--> {{arity:3, nothing:true}, {arity:0, nothing:false, just:"hello world!"}}
end run
-- SAMPLE HANDLERS TO TEST FOR ARITY AT RUN-TIME -----------------------------
-- helloWorld ::() -> String
on helloWorld()
"hello world!"
end helloWorld
-- zipWith :: (a -> b -> c) -> [a] -> [b] -> [c]
on zipWith(f, xs, ys)
set lng to min(length of xs, length of ys)
set lst to {}
tell mReturn(f)
repeat with i from 1 to lng
set end of lst to |λ|(item i of xs, item i of ys)
end repeat
return lst
end tell
end zipWith
-- GENERIC FUNCTIONS ---------------------------------------------------------
-- splitOn :: Text -> Text -> [Text]
on splitOn(strDelim, strMain)
set {dlm, my text item delimiters} to {my text item delimiters, strDelim}
set xs to text items of strMain
set my text item delimiters to dlm
return xs
end splitOn
-- Lift 2nd class handler function into 1st class script wrapper
-- mReturn :: Handler -> Script
on mReturn(f)
if class of f is script then
f
else
script
property |λ| : f
end script
end if
end mReturn
1) 아니오 - 2) 아니오 – vadian
(1)인가하지 물론, 기술적으로 불가능 - 우리가 확실히 실행시 오류 메시지 문자열을 긁어 수 있습니다 -하지만 청소기 뭔가 좋은 것입니다.하지 – houthakker