This tutorial is for those who want to understand lambda calculus without having to use the original syntax.
It is based in JavaScript. You need to know Arrow Functions in JavaScript. You can try the examples in the browser console, or NodeJS REPL.
Lambda Calculus is a simple but powerful language based on pure abstraction.
It is made up of three types of expressions.
This is not so hard to understand, if you consider abstractions to be functions, and applications…
All the code in this article is available as a Github Project. https://github.com/santoshrajan/LayoutSwift
In Swift we use the Objective-C UIKit framework to layout components on the screen, using Storyboard, Constraints etc. In this article we will explore the possibilities of creating layouts without using Storyboards and Constraints, in Swift.
Most layouts will fall into one of the following three categories.
Create a Single…
Slides of my talk at the first Bangalore Swift Meetup
Previous Posts
In this post we will write some HTTP wrapper functions. The Objective is that you can use them even if you don’t understand Objective-C. The three most useful functions are HTTPGet, HTTPGetJSON, HTTPPostJSON. I will leave it to the readers to write other HTTP functions.
First we create function called HTTPsendRequest. You don’t have to call this function directly. This function is used by our GET and POST requests.
The HTTPGet function takes two parameters. A String url and a callback function. The callback…
Previous Posts
In Swift you can use Objective-C classes. You can import builtin SDK frameworks/modules into Swift. Type the following and run the program.
import Foundation
Don’t be surprised if you get an error. (In case you got one).
JSON.swift:1:8: error: cannot load underlying module for ‘Foundation’
import Foundation
^
<unknown>:0: note: did you forget to set an SDK using -sdk or SDKROOT?
<unknown>:0: note: use “-sdk $(xcrun —show-sdk-path —sdk macosx)” to select the default OS X SDK installed with Xcode
To fix this set SDKROOT environment variable.
$ export…
Previous Posts
Take the each function from the previous post. Simplify it a little such that the callback takes one argument. We will not pass the Array index as argument, only the Array element.
func each<T>(array: [T], callback: (T) -> Void) {
for elem in array {
callback(elem)
}
}each([1, 2, 3, 4],callback: print)
And here is the output.
$ xcrun swift -i test.swift
1
2
3
4
Now the callback is called for each element of the Array with the corresponding element. We call each with an Array, and print as…
This is a follow up to the previous post
1. Learn Swift by running Scripts
Look at the last example from the previous article
func square(x: Int) -> Int {
return x * x
}var num: Int? = nilif let newnum = num {
print(square(newnum))
} else {
print(“num is nil”) // prints - num is nill
}
Now try this
func square(x: Int) -> Int {
return x * x
}var num: Int? = nilprint(num.map(square)) // prints nilnum = 10print(num.map(square)) // prints Optional(100)
Wow! What was that? Take a closer look
num.map(square)
We…
May be it is only me, or you are like me. I like to learn a language by writing little Scripts in that language. You can write and execute Swift Scripts using the immediate mode of the Swift language compiler.
First download and install Xcode 7.
The Swift interpreter is called, not surprisingly swift. First something about the REPL before I show you how to run scripts. Running the Swift interpreter without any command line arguments will run the REPL. Now run the Swift REPL by typing swift into the terminal. …
Recursion is the process in which a function is called by itself, either directly or indirectly. Recursion allows you to write some very elegant code. But when using recursion you need to be aware of the pitfals.
Here is a function that will call itself a given number of times.
function factorial(n, accumulator) {
if (n === 0) {
return accumulator
}
return factorial(n — 1, n * accumulator)
}
factorial(5, 1) //==>> 120
The function above will recursively call the factorial function from 5 to 0 with an accumulator value. The condition n === 0 is the break condition…
Founder www.geekskool.com. Programmer for over 30 years. Making better programmers is my passion. Bangalore. India. www.santoshrajan.com