0 Members and 1 Guest are viewing this topic.
Do any of you have examples of a function something similar to mapcar (in LISP) for use with .net collections?
using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Runtime; using System.Linq; using System.Collections.Generic; public class Class1 { [CommandMethod("Foo")] public void Foo(){ Database db = Application.DocumentManager.MdiActiveDocument.Database; using (Transaction tr = db.TransactionManager.StartTransaction()){ BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); IEnumerable<ObjectId> btseq = bt.Cast<ObjectId>(); IEnumerable<BlockTableRecord> btrs1 = btseq.Select(oid => (BlockTableRecord)tr.GetObject(oid, OpenMode.ForRead)); IEnumerable<BlockTableRecord> btrs2 = from oid in btseq select (BlockTableRecord)tr.GetObject(oid, OpenMode.ForRead); tr.Commit(); } } }
OK how about a mapcar like expression or function that works with arrays?Like I want to convert an array of fullnames to an array of filenames for a list box control.
using System.IO; ... string[] files = Directory.GetFiles("c:/temp").Select(fqn => Path.GetFileName(fqn)).ToArray();
let file = Directory.GetFiles("C:\\Temp") |> Array.map(fun f -> Path.GetFileName(f))
If you want to use .NET with a more 'LISP like style', why not using F#:Code: [Select]let file = Directory.GetFiles("C:\\Temp") |> Array.map(fun f -> Path.GetFileName(f))
open System.IOlet getFileNamesOnly = Directory.GetFiles >> Array.map Path.GetFileNamegetFileNamesOnly @"C:\Temp"