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.

  1. Variables, that evaluate to a value
  2. Abstractions, that evaluate to an anonymous function
  3. Applications i.e. application of the anonymous functions.

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.

  1. Vertical Layout — Sub Views are laid out vertically one below the other.
  2. Horizontal Layout — Sub Views are laid out horizontally one after the other from left to right.
  3. A Combination of the above two layouts.

Create a Single…


GET, GETJSON, POSTJSON

Previous Posts

  1. Learn Swift by running Scripts
  2. Functional Swift
  3. More Functional Swift
  4. JSON in Swift

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…


JSONStringify and JSONParse functions

Previous Posts

  1. Learn Swift by running Scripts
  2. Functional Swift
  3. More Functional Swift

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…


Closures, Recursion

Previous Posts

  1. Learn Swift by running Scripts
  2. Functional Swift

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…


Functional Programming in the Swift Language

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…


Learn using command line Scripts without using Xcode UI

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. …


If you know of any more video tutorials please post link in comment so that I can add it.

Developing ios8 apps with swift — Stanford — iTunes U

Swift Hello World Video Tutorial

https://www.youtube.com/watch?v=w_0QPVG2pQk

Swift WebView

https://www.youtube.com/watch?v=-wQ8sVa9TbU

Swift iOS Tutorial — Build a Checklist App: Part One

https://www.youtube.com/watch?v=WsvrQgsZ13I

Swift iOS Tutorial — Build a Checklist App: Part Two

https://www.youtube.com/watch?v=Tq0nkr9nhyk

Swift Timer Application

https://www.youtube.com/watch?v=a7gX2v6M30w&feature=youtu.be


Recursion, Tail Calls, Proper Tail Calls, Examples

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.

Recursion example

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…

Santosh Rajan

Founder www.geekskool.com. Programmer for over 30 years. Making better programmers is my passion. Bangalore. India. www.santoshrajan.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store