2017-07-17 5 views
0

Ich las this Artikel und ich über die folgenden zwei Funktionen kamen:Was ist das Schlüsselwort "const" in Swift?

// Sequence actions, discarding the value of the second argument 
func <* <A, B>(p: Parser<A>, q: Parser<B>) -> Parser<A> { 
    return const <^> p <*> q 
} 

// Sequence actions, discarding the value of the first argument 
func *> <A, B>(p: Parser<A>, q: Parser<B>) -> Parser<B> { 
    return const(id) <^> p <*> q 
} 

Was sind die const und const(id)? Ich vermute, dass es sich um Werte handelt, aber welche Werte? Sind sie implizite links- oder rechtsseitige Operanden? (Dies ist nur eine Einstellung im Dunkeln). Ich konnte keine Informationen darüber finden.

+1

Ich glaube, diese Funktionen in seinem Parser sind nicht Teil der Stiftung. – Rob

+0

@Rob ah das würde Sinn machen! –

+1

https://github.com/tryswift/TryParsec/blob/4dc2cadc23311fc27dbcbd108727bab46905e229/Sources/TryParsec/Prelude.swift#L7 – Hamish

Antwort

1

Swift hat kein const Schlüsselwort.

Der Vortrag verwendet the TryParsec library, die this const function definiert:

/// Constant function. 
internal func const<A, B>(_ a: A) -> (B) -> A 
{ 
    return { _ in a } 
} 
Verwandte Themen