JoyCog

Check-in [e2673caf01]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Oooh, starting to get the hang of this. Ratios takes littlegears as arg

Biggears is still defined inline, but ratios is now a proper function.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | origin/master | trunk
Files: files | file ages | folders
SHA3-256: e2673caf01baf1a294ca2dc49d85dbd324f1fd10d1a17073ba142d3c7fb9731e
User & Date: base@atomicules.co.uk 2014-02-06 13:07:16
Context
2014-02-07
23:42
Finish programme. Can now supply function the two lists

- Add commentary for the state of the stack so I can understand what the
hell is going on
- Add examples and description
- Two functions. Extend work from last commit to make `ratios` which
given a number and a list creates the list of triples
- Figure out the main programme so can supply the two lists check-in: 364c19db20 user: base@atomicules.co.uk tags: origin/master, trunk

2014-02-06
13:07
Oooh, starting to get the hang of this. Ratios takes littlegears as arg

Biggears is still defined inline, but ratios is now a proper function. check-in: e2673caf01 user: base@atomicules.co.uk tags: origin/master, trunk

10:17
Correct qsort1, don't nest gear pairs, build up triples and concat

The qsort1 definition was wrong, hence the comment about the wrong
result. I'd forgot that `swap23` mentioned here:

http://www.kevinalbrecht.com/code/joy-mirror/j06prg.html

isn't just `swap`, but rather `[swap] dip`. However, before I realised
that I wondered if the nested gear pairs was the issue and decided to
build up a flatter list. I.e. [ [ 4.16667 12 50] ... ] as opposed to
[ [ 4.16667 [12 50] ] ... ]. I think I prefer this approach anyway as
rather than build up a list of ratios, then a list of pairs and then zip
these together, can build up two lists of triples and just concat these. check-in: 4535761621 user: base@atomicules.co.uk tags: origin/master, trunk

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to joycog.joy.

1
2
3
4
5
6
7









8

9
10
11
12
13
14
15
16
17




18

19
20
21
22
23

24

25
26
27
28
29
30
31


32
33
34
35
36
37
38
39
40
(* joycog.joy *)
(* Given two lists of gear sprockets will calculate all ratios *)

DEFINE

	(* Constants. Ultimately these want to be arguments to the programme *)










	littlegears == [12 13 15 17 19 21 23 26];

	biggears == [34 50];

	(* Build up list of ratios and gear pairs *)

	biggear1 == biggears first
	            1.0 *;
	biggear2 == biggears second
	            1.0 *;





	ratios1 == littlegears dup

	           [biggear1 swap /] map
	           swap
	           zip
	           [biggear1 unitlist concat] map;


	ratios2 == littlegears dup

	           [biggear2 swap /] map
	           swap
	           zip
	           [biggear2 unitlist concat] map;
	
	ratios == ratios1 ratios2 concat;



	(* Sort *)

	qsort1 == [ small ]
	          [ ]
	          [ uncons [[first] unary2 > ] split ]
	          [ [swap] dip cons concat ]
	          binrec;

	sorted == ratios qsort1.





|

>
>
>
>
>
>
>
>
>
|
>


<
<





>
>
>
>
|
>





>
|
>




<
<
<
>
>
|
<
|
<
<
<
<
<
<
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43



44
45
46

47






(* joycog.joy *)
(* Given two lists of gear sprockets will calculate all ratios *)

DEFINE

	(* Sort Routine *)

	qsort1 == [ small ]
	          [ ]
	          [ uncons [[first] unary2 > ] split ]
	          [ [swap] dip cons concat ]
	          binrec;

	(* Constants *)

	(* littlegears is now the argument to ratios *)
	(* littlegears == [12 13 15 17 19 21 23 26]; *)

	biggears == [34 50];



	biggear1 == biggears first
	            1.0 *;
	biggear2 == biggears second
	            1.0 *;

	(* Ratios Routine *)

	ratios ==
	           dup
(* Ratios1 *)
	           dup
	           [biggear1 swap /] map
	           swap
	           zip
	           [biggear1 unitlist concat] map;

	           swap
(* Ratios2 *)
	           dup
	           [biggear2 swap /] map
	           swap
	           zip
	           [biggear2 unitlist concat] map;



(* Join *)
	           concat
(* sort *)

	           qsort1.