Skip to content

Instantly share code, notes, and snippets.

View tayloraswift's full-sized avatar

taylorswift tayloraswift

View GitHub Profile
@tayloraswift
tayloraswift / single-quoted-character-literals.md
Last active December 12, 2022 23:44
Single-quoted character literals
@tayloraswift
tayloraswift / vscode+docker tutorial.md
Last active August 21, 2022 21:29
vscode+docker tutorial

test project

  1. clone a swift project

installing code

  1. download from https://code.visualstudio.com/

setting up the vscode-swift extension

module: '_Differentiation@Swift', id: 's:s4SIMDPsSF6ScalarRpzrlE2meoiyyxz_xtFZ::SYNTHESIZED::s:s5SIMD2V'
module: '_Differentiation@Swift', id: 's:s4SIMDPss17FixedWidthInteger6ScalarRpzrlE1doiyxAE_xtFZ::SYNTHESIZED::s:s5SIMD8V'
module: '_Differentiation@Swift', id: 's:s4SIMDPss17FixedWidthInteger6ScalarRpzrlE4alleoiyyxz_xtFZ::SYNTHESIZED::s:s5SIMD3V'
module: '_Differentiation@Swift', id: 's:s4SIMDPss17FixedWidthInteger6ScalarRpzrlE2seoiyyxz_AEtFZ::SYNTHESIZED::s:s5SIMD8V'
module: '_Differentiation@Swift', id: 's:s4SIMDPss17FixedWidthInteger6ScalarRpzrlE1aoiyxx_xtFZ::SYNTHESIZED::s:s5SIMD2V'
module: '_Differentiation@Swift', id: 's:s4SIMDPsSF6ScalarRpzrlE1poiyxAD_xtFZ::SYNTHESIZED::s:s5SIMD4V'
module: '_Differentiation@Swift', id: 's:s4SIMDPsEyxqd__cSTRd__7ElementQyd__6ScalarRtzlufc::SYNTHESIZED::s:s5SIMD4V'
module: '_Differentiation@Swift', id: 's:s4SIMDPss17FixedWidthInteger6ScalarRpzrlE20trailingZeroBitCountxvp::SYNTHESIZED::s:s5SIMD4V'
module: '_Differentiation@Swift', id: 's:s4SIMDPss17FixedWidthInteger6Sc
module: 'NIOConcurrencyHelpers@Swift', id: 's:SzsE2lloiyxx_qd__tSzRd__lFZ::SYNTHESIZED::s:s5Int64V'
module: 'NIOConcurrencyHelpers@Swift', id: 's:s18AdditiveArithmeticPsE1popyxxFZ::SYNTHESIZED::s:s4Int8V'
module: 'NIOConcurrencyHelpers@Swift', id: 's:SzsE1goiySbx_xtFZ::SYNTHESIZED::s:s4Int8V'
module: 'NIOConcurrencyHelpers@Swift', id: 's:SZss17FixedWidthIntegerRzrlEyxqd__cSzRd__lufc::SYNTHESIZED::s:s5Int16V'
module: 'NIOConcurrencyHelpers@Swift', id: 's:s18AdditiveArithmeticPss27ExpressibleByIntegerLiteralRzrlE4zeroxvpZ::SYNTHESIZED::s:s5Int16V'
module: 'NIOConcurrencyHelpers@Swift', id: 's:s17FixedWidthIntegerPsE2apoiyxx_xtFZ::SYNTHESIZED::s:Su'
module: 'NIOConcurrencyHelpers@Swift', id: 's:s17FixedWidthIntegerPsE3ggeoiyyxz_qd__tSzRd__lFZ::SYNTHESIZED::s:s6UInt16V'
module: 'NIOConcurrencyHelpers@Swift', id: 's:SZsE8isSignedSbvpZ::SYNTHESIZED::s:s5Int32V'
module: 'NIOConcurrencyHelpers@Swift', id: 's:s17FixedWidthIntegerPsE3ggeoiyyxz_qd__tSzRd__lFZ::SYNTHESIZED::s:s5Int32V'
module: 'NIOConcurrencyHelpers@Swif

Swift integer literals

introduction

Swift allows you to initialize any type from an integer literal in source code by conforming it to the ExpressibleByIntegerLiteral protocol. Currently, Int8, Int16, Int32, Int64, Int, and their unsigned counterparts are supported as bootstrap types when the compiler emits code passing source code literals to an ExpressibleByIntegerLiteral.init(integerLiteral:) implementation. This effectively caps the maximum supported integer literal width to 64 bits.

This proposal aims to unlock arbitrary-precision integer literals in a way that:

  • will decouple the compile-time overflow checking from the actual passed integer value storage,
  • will eliminate the need for magic underscored protocols,
import func Glibc.fopen
import func Glibc.fseek
import func Glibc.ftell
import func Glibc.fclose
import func Glibc.fread
import func Glibc.fwrite
import func Glibc.strerror
import var Glibc.errno
import sys
text = sys.argv[1]
def hue(angle):
h = angle / 60
x = 1 - abs(h % 2 - 1)
return ((1, x, 0), (x, 1, 0), (0, 1, x), (0, x, 1), (x, 0, 1), (1, 0, x))[int(h)]
def hexcolor(rgb):
import func Glibc.atan2
infix operator <> :MultiplicationPrecedence // dot product
infix operator >< :MultiplicationPrecedence // cross product
infix operator &<> :MultiplicationPrecedence // wrapping dot product
infix operator &>< :MultiplicationPrecedence // wrapping cross product
infix operator ~~ :ComparisonPrecedence // distance test
infix operator !~ :ComparisonPrecedence // distance test
import func Glibc.sin
import func Glibc.cos
import func Glibc.tan
import func Glibc.asin
import func Glibc.acos
import func Glibc.atan
import func Glibc.atan2
infix operator <> :MultiplicationPrecedence // dot product
infix operator >< :MultiplicationPrecedence // cross product
@tayloraswift
tayloraswift / vectormanifesto.md
Last active June 28, 2020 01:54
the vector manifesto

Vector manifesto

Vectors, understood as 2, 3, or 4-component numerical aggregates, are a fundamental currency type across many domains of programming. This document seeks to lay out a cohesive vision for adding standard vector support to the Swift language, with consideration for relevant long-term goals for the language type system.

Past discussions: 1 2, 3, 4, 5

Past pitches: 1

Vectors and fixed-size arrays